我已经按行列举了我的文本,但它不在行的中间,我不知道如何实现这一点。
我的 MWE:
\documentclass{article}
\usepackage{array,tabularx,multirow,geometry}
\geometry{paper=a4paper,left=30mm,right=25mm,top=30mm}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\let\oldtabularx\tabularx
\renewcommand{\tabularx}{\setcounter{rowcount}{-1}\oldtabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|@{\space\stepcounter{rowcount}\ifnum\value{rowcount}=0\else\therowcount.\thinspace\fi}X|X|}
\hline
\textbf{Typologie} & \textbf{Subgruppe} \\
\hline
\hline
Lorem ipsum dolor sit amet & consectetuer adipiscing elit. Etiam lobortis facilisis sem.
\\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
\end{tabularx}
\end{document}
我已经尝试过\multirows
,\renewcommand\tabularxcolumn[1]{m{#1}}
但是这只会产生其他布局问题。
答案1
尝试这个:
\documentclass{article}
\usepackage{array,tabularx,multirow,geometry}
\geometry{paper=a4paper,left=30mm,right=25mm,top=30mm}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\let\oldtabularx\tabularx
\renewcommand{\tabularx}{\setcounter{rowcount}{-1}\oldtabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|>{\stepcounter{rowcount}\ifnum\value{rowcount}=0\else\therowcount.\thinspace\fi\hangindent=1em}X|X|}
\hline
\textbf{Typologie} & \textbf{Subgruppe} \\
\hline
\hline
Lorem ipsum dolor sit amet & consectetuer adipiscing elit. Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
\end{tabularx}
\end{document}
输出:
如果需要超过 9 行,我们可以定义一个新的列类型N
:
\newcolumntype{N}{>{\stepcounter{rowcount}%
\ifnum\value{rowcount}=0\else\therowcount.\thinspace\fi%
\ifnum\value{rowcount}>9\hangindent=1.5em\else\hangindent=1em\fi}X}
因此 MWE
\documentclass{article}
\usepackage{array,tabularx,multirow,geometry}
\geometry{paper=a4paper,left=30mm,right=25mm,top=30mm}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\let\oldtabularx\tabularx
\renewcommand{\tabularx}{\setcounter{rowcount}{-1}\oldtabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\newcolumntype{N}{>{\stepcounter{rowcount}%
\ifnum\value{rowcount}=0\else\therowcount.\thinspace\fi%
\ifnum\value{rowcount}>9\hangindent=1.5em\else\hangindent=1em\fi}X}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|N|X|}
\hline
\textbf{Typologie} & \textbf{Subgruppe} \\
\hline
\hline
Lorem ipsum dolor sit amet & consectetuer adipiscing elit. Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
\end{tabularx}
\end{document}
产量
答案2
我几乎明白你在寻找什么了...我只是缺少文本的对齐,但希望有人能解决这个问题!
以下是 MWE:
\documentclass{article}
\usepackage{array,geometry}
\geometry{paper=a4paper,left=30mm,right=25mm,top=30mm}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\let\oldtabular\tabular
\renewcommand{\tabular}{\setcounter{rowcount}{-1}\oldtabular}
\begin{document}
\begin{tabular}{|>{\stepcounter{rowcount}\raggedright\arraybackslash\ifnum\value{rowcount}=0\else\therowcount.~\fi}m{0.5\textwidth}|m{0.5\textwidth}}
\hline
\textbf{Typologie} & \textbf{Subgruppe} \\
\hline
\hline
Lorem ipsum dolor sit amet & consectetuer adipiscing elit. Etiam lobortis facilisis sem.
\\
\hline
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. & Etiam lobortis facilisis sem. \\
\hline
\end{tabular}
\end{document}
我的解决方案使用tabular
环境和>{<cmd>}
选项,而不是@{<cmd>}
第一列的选项。这确保计数器与单元格的第一个单词处于同一级别。然后为了垂直对齐它,我只需使用列m
描述符。
输出如下:
笔记如果文本需要分布在多行上,单元格中的文本水平对齐仍然存在问题。文本在数字下“重新开始”,而不是在上一行的第一个单词下,这似乎是图片上所希望的。
编辑我只是错过了这个\hangindent
功能...请参阅 karlkoeller 的回答来解决这个问题。