我在将文本定位到表格单元格的第一行时遇到了问题。如果有人能帮助我解决这个问题,我将不胜感激。
代码如下:
\documentclass{article}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\begin{document}
\begin{tabular}{| L{3cm} | L{3cm} | C{3cm} | R{3cm} |}
\hline
foo &
\tabitem A cell with text that wraps around\newline
\tabitem is raggedright and allows
manual line breaks &
\tabitem A cell with text that wraps around
&
A cell with text that wraps around, is raggedleft and allows
\newline
manual line breaks \\
\hline
\end{tabular}
\end{document}
\end{document}
该表现在如下所示:
预先感谢您的帮助
答案1
使用p
列而不是m
让文本从单元格顶部开始。此外,itemize
在适当调整参数以适应tabular
s 后,可以使用 normal。
\documentclass{article}
\usepackage{enumitem,array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash}p{#1}}
\begin{document}
\setlist[itemize]{leftmargin = *, itemsep=-3pt, before=\vspace*{-\dimexpr\baselineskip+\partopsep}, after=\vspace*{\dimexpr-\baselineskip+\partopsep}}
\begin{tabular}{| L{3cm} | L{3cm} | C{3cm} | R{3cm} |}
\hline
foo
&
\begin{itemize}
\item A cell with text that wraps around
\item is raggedright and allows manual line breaks
\end{itemize}
&
\begin{itemize}
\item A cell with text that wraps around
\end{itemize}
&
A cell with text that wraps around, is raggedleft and allows \newline
manual line breaks \\ \hline
\end{tabular}
\end{document}