2

I have a problem with the indentation done by the addmargin environment of the koma script and the use of tabularx table. Clearly the \textwidth uses the original width of the text and not the smaller one of the addmargin environment.

So the desired output is that the table is left aligned with the lipsum[1] text and right aligned both with the lipsum[1] and lipsum[2] text.

MWE:

\documentclass{scrbook}
\usepackage{tabularx}
\usepackage{lipsum}


\begin{document}
\lipsum[2]
\begin{addmargin}[2\parindent]{0pt}
    \lipsum[1]  
\begin{tabularx}{\textwidth}{p{.2\textwidth}X}
    First column & A long column which doesn't respect the margin added to the left of this page but goes into the margin on the right \\
    Second column & A long column which doesn't respect the margin added to the left of this page but goes into the margin on the right \\
\end{tabularx}
\end{addmargin}
\end{document}
3
  • 1
    tabularx is very respectful and does what it's told, even if you tell it the wrong thing: use \linewidth not \textwidth Jul 10, 2014 at 17:02
  • @DavidCarlisle OK I should have formulated it a bit different. It didn't mean that the package can't do it, but that I did not get the desired output with the settings I used. Jul 10, 2014 at 17:35
  • I know, just joking with you:-) Jul 10, 2014 at 17:58

1 Answer 1

4

The \textwidth doesn't change: you have to use \linewidth when inside a list (which addmargin is); moreover you have to remember \noindent and @{} for removing the padding on the left and right.

\documentclass{scrbook}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}
\lipsum[2]

\begin{addmargin}[2\parindent]{0pt}
\lipsum[1]

\noindent
\begin{tabularx}{\linewidth}{@{}p{.2\textwidth}X@{}}
    First column & A long column which doesn't respect the margin added to the left of this page but goes into the margin on the right \\
    Second column & A long column which doesn't respect the margin added to the left of this page but goes into the margin on the right \\
\end{tabularx}
\end{addmargin}

\end{document}

enter image description here

On the other hand, tabularx is not needed:

\documentclass{scrbook}
\usepackage{calc}
\usepackage{lipsum}


\begin{document}
\lipsum[2]
\begin{addmargin}[2\parindent]{0pt}
\lipsum[1]  

\noindent
\begin{tabular}{@{}p{.2\linewidth}p{.8\linewidth-2\tabcolsep}@{}}
    First column & A long column which doesn't respect the margin added to the left of this page but goes into the margin on the right \\
    Second column & A long column which doesn't respect the margin added to the left of this page but goes into the margin on the right \\
\end{tabular}
\end{addmargin}

\end{document}
1
  • 1
    I'd just made an identical answer but I suppose I'll +1 yours since you were so kind to me earlier:-) Jul 10, 2014 at 17:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .