我有下表:
\begin{table}
\begin{tabular}{ | p{2cm} | p{9cm} |}
\hline
\textbf{Heading 1} & \textbf{Heading 2} \\ \hline
Foo & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et\tabularnewline \hline
Foo Ba Foo Ba Foo Ba & \centering \checkmark \tabularnewline \hline
\end{tabular}
\end{table}
我希望复选标记垂直对齐。我尝试过,\vcenter \centering \checkmark \tabularnewline \hline
但出现了很多错误。
任何帮助将不胜感激。
答案1
\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{ | p{2cm} | p{9cm} |}
\hline
\textbf{Heading 1} & \textbf{Heading 2} \\ \hline
Foo & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et\tabularnewline \hline
Foo Ba Foo Ba Foo Ba & \vfil\hfil $\heartsuit$ \tabularnewline \hline
\end{tabular}
\end{table}
\end{document}
答案2
套餐multirow
提供\multirow
,可用于垂直居中/移动材料。这里,这有点过头了,必须手动添加行数,请参阅回答Przemysław Scherwentk 的使用 的更短的解决方案\vfil
。
\documentclass{article}
\usepackage{multirow}
\usepackage{pifont}
\providecommand*{\checkmark}{\ding{51}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ | p{2cm} | p{9cm} |}
\hline
\textbf{Heading 1} & \textbf{Heading 2} \\ \hline
Foo & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et\tabularnewline
\hline
Foo Ba Foo Ba Foo Ba &
\multirow{2}{\linewidth}{\centering\checkmark}\tabularnewline
\hline
\end{tabular}
\end{table}
\end{document}
使用包的版本行数更少booktabs
:
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{pifont}
\providecommand*{\checkmark}{\ding{51}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ p{2cm} p{9cm} }
\toprule
\textbf{Heading 1} & \textbf{Heading 2} \\
\midrule
Foo & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et\tabularnewline
\addlinespace
Foo Ba Foo Ba Foo Ba &
\multirow{2}{\linewidth}{\centering\checkmark}\tabularnewline
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
另一种解决方案(稍微复杂一些):
\documentclass[border=3mm,
preview]{standalone}
\usepackage{amsmath,amssymb}
\usepackage{makecell,multirow}% added
\begin{document}
\begin{table}
\begin{tabular}{ |p{2cm}|p{9cm}|}
\hline
\textbf{Heading 1} & \textbf{Heading 2} \\ \hline
Foo & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et\tabularnewline \hline
Foo Ba Foo Ba Foo Ba & \multirowcell{2}{\checkmark} \\ \hline
\end{tabular}
\end{table}
\end{document}