ipofanes
ipofanes

Reputation: 11

width of tabularx longer than columnwidth in multicol environment

In a multicol environment, I would like to generate a table which spans the width of a current column. Instead, tables excede columns.

\documentclass{scrartcl}

\usepackage{tabularx}
\usepackage{multicol}
\usepackage{showframe}
\usepackage{blindtext}
\setlength{\parindent}{0mm}
\begin{document}
\begin{multicols}{2}
  \framebox{%
    \begin{tabularx}{1.0\columnwidth}{Xrr}
      \blindtext & Max & Moritz
    \end{tabularx}
    }
    left \hrulefill right
    \framebox{%
    \begin{tabularx}{1.0\columnwidth}{Xrr}
      \blindtext & Moritz & Max
    \end{tabularx}
  }
  left \hrulefill right
\end{multicols}
\end{document}

I expect the tables to be span the left-right line, instead, the first table spans the space from the first to the second "left".

page with blindtext and boxes depicting the behaviour of tabularx

Upvotes: 1

Views: 159

Answers (1)

Your tables are exactly the width of the column, but you are adding some space around them:

  • there will be some padding between the framebox and its content. You can disable this by setting the \fboxsep to zero

  • the missing % after your tables will act like one additional space


\documentclass{scrartcl}

\usepackage{tabularx}
\usepackage{multicol}
\usepackage{showframe}
\usepackage{blindtext}
\setlength{\parindent}{0mm}

\setlength{\fboxsep}{0pt}
\begin{document}
\begin{multicols}{2}
  \framebox{%
    \begin{tabularx}{1.0\columnwidth}{Xrr}
      \blindtext & Max & Moritz
    \end{tabularx}%
    }
    left \hrulefill right
    \framebox{%
    \begin{tabularx}{1.0\columnwidth}{Xrr}
      \blindtext & Moritz & Max
    \end{tabularx}%
  }
  left \hrulefill right
\end{multicols}
\end{document}

enter image description here

Upvotes: 0

Related Questions