tabularx 表和来自 addmargin 环境的缩进

tabularx 表和来自 addmargin 环境的缩进

我对 koma 脚本的 addmargin 环境所做的缩进和 tabularx 表格的使用存在疑问。显然,它\textwidth使用的是文本的原始宽度,而不是 addmargin 环境的较小宽度。

因此,期望的输出是表格与lipsum[1]文本左对齐,与lipsum[1]lipsum[2]文本右对齐。

梅威瑟:

\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}

答案1

不会\textwidth改变:您必须\linewidth在列表内使用addmargin;此外,您必须记住\noindent@{}删除左侧和右侧的填充。

\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}

在此处输入图片描述

另一方面,tabularx不需要:

\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}

相关内容