2

When I use multicolumn in a tabular table, the text is always indented compared to the other rows where no multicolumn is defined.

How can I solve this?

\documentclass{article}

\usepackage{multicol}                           % define a multicols environment which typesets text in multiple columns
\usepackage{colortbl}                           % background color for row, columns or individual cells in a table
\usepackage{xcolor}                             % foreground (text, rules, etc.) and background colour management

\definecolor{beige}{cmyk}{0.16,0.03,0.31,0}
\definecolor{shamrock}{cmyk}{0.71,0.29,1,0.13}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}    % define a new column type for a fixed-width right-aligned column - middle vertical alignment
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}   % define a new column type for a fixed-width left-aligned column - middle vertical alignment

\begin{document}

\begin{tabular}{L{110mm} R{35mm}} 
    \cellcolor{beige}
    \textbf{Column title} 
    & \cellcolor{beige}
    \textbf{99.999,99 EUR} \\
    \multicolumn{2}{L{145mm}}{
        \color{shamrock}I don't understand why this text is left indented. The other text
        is not indented in the table. I don't understand why this text is left indented. The other text
        is not indented in the table.
    } \\
    \color{shamrock}Title: 
    & \color{shamrock}99.999,99 EUR \\
\end{tabular}

\end{document}

2 Answers2

3

The size of the \multicolumn doesn't take into account the two \tabcolsep between the columns.

In the example below I use m, so the center multicolumn cell is justified.

Note that multicol has no bearing with this example; instead of loading first colortbl and then xcolor, it's better to load just the latter with the table option.

\documentclass{article}

\usepackage[table]{xcolor}

\definecolor{beige}{cmyk}{0.16,0.03,0.31,0}
\definecolor{shamrock}{cmyk}{0.71,0.29,1,0.13}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}

\begin{document}

\begin{tabular}{L{110mm} R{35mm}} 
\cellcolor{beige}\textbf{Column title} & \cellcolor{beige}\textbf{99.999,99 EUR} \\
\multicolumn{2}{m{\dimexpr145mm+2\tabcolsep}}{%
  \color{shamrock}I don't understand why this text is left indented. The other text
  is not indented in the table. I don't understand why this text is left indented.
  The other text is not indented in the table.
} \\
\color{shamrock}Title: & \color{shamrock}99.999,99 EUR \\
\end{tabular}

\end{document}

enter image description here

egreg
  • 1,121,712
1

The m column type isn't factoring in the inter-column separation of the two columns, so your specified \multicolumn width is shorter than the actual width of the table. For reasons that aren't entirely clear to me, \multicolumn then aligns the text so that the right edge is flush with the end of the second column. Note that p and b don't behave this way. The effect is very obvious if you reduce the \multicolumn width even more. (Try reducing the width to 100mm to see what I mean.)

The easiest way to fix it is to eliminate the inter-column spacing between the two ordinary columns:

\documentclass{article}
\usepackage{array}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\begin{document}
\begin{tabular}{L{110mm}@{}R{35mm}} 
  \textbf{Column title}  & \textbf{99.999,99 EUR} \\
  \multicolumn{2}{L{145mm}}{
      CI don't understand why this text is left indented. The other text 
        is not indented in the table. I don't understand why this text is left indented. The other text
        is not indented in the table.
    } \\
  Title: & 99.999,99 EUR \\
\end{tabular}
\end{document}

Result:

enter image description here

Karl Hagen
  • 1,540