我想创建一个垂直和水平对齐的表格。我使用以下脚本如何垂直对齐表格中的符号?目前,它们会自动对齐,我无法使它们居中。
编辑:我希望复选标记和 xmark 符号在其单元格内垂直和水平对齐
\begin{table}[]
\caption {Caption title}
\centering
\hspace*{-2.2cm}
\resizebox{1.3\textwidth}{!}{%
\begin{tabular}{|p{5cm}|l|l|l|l|p{1cm}|}
\hline
\multicolumn{1}{|c|}{\textbf{Title}} &
\textbf{A} &
\textbf{B} &
\textbf{C} &
\textbf{D} &
\textbf{E}
\\ \hline
Some text, in some cases a little paragraph &
\multicolumn{1}{|M|}{\checkmark} &
\multicolumn{1}{|c|}{\xmark} &
\multicolumn{1}{|c|}{\checkmark} &
\multicolumn{1}{|c|}{\xmark } &
\multicolumn{1}{|c|}{
Ref number
}
\\ \hline
\end{tabular}%
}
答案1
永远不要调整表格大小。为什么1.3\textwidth
?你真的想让表格超出页边距吗?
\documentclass{article}
\usepackage{array}
\usepackage{caption}
\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\begin{document}
\begin{table}
\centering
\caption{This is the caption}\label{label}
\begin{tabular}{
| m{5cm} | *{4}{w{c}{1em}|} l |
}
\hline
\multicolumn{1}{|c|}{\textbf{Title}} &
\textbf{A} &
\textbf{B} &
\textbf{C} &
\textbf{D} &
\textbf{E}
\\ \hline
Some text, in some cases a little paragraph &
\cmark & \xmark & \cmark & \xmark & Ref number
\\ \hline
\end{tabular}
\end{table}
\end{document}
您可以考虑避免使用笼状表格。在这种情况下,顶部对齐似乎更容易且更好(表格 2)。
\documentclass{article}
\usepackage{array,booktabs}
\usepackage{caption}
\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\begin{document}
\begin{table}[htp]
\centering
\caption{This is the caption}\label{label}
\begin{tabular}{
m{5cm} *{4}{w{c}{1em}} l
}
\toprule
\multicolumn{1}{c}{Title} & A & B & C & D & E \\
\midrule
Some text, in some cases a little paragraph &
\cmark & \xmark & \cmark & \xmark & Ref number
\\
\addlinespace
Some text, in some cases a little paragraph &
\cmark & \xmark & \cmark & \xmark & Ref number
\\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[htp]
\centering
\caption{Another version}
\begin{tabular}{
p{5cm} *{4}{w{c}{1em}} l
}
\toprule
\multicolumn{1}{c}{Title} & A & B & C & D & E \\
\midrule
Some text, in some cases a little paragraph &
\cmark & \xmark & \cmark & \xmark & Ref number
\\
\addlinespace
Some text, in some cases a little paragraph &
\cmark & \xmark & \cmark & \xmark & Ref number
\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
含tabulčarray
包装:
\documentclass{article}
\usepackage{pifont}
\newcommand\cmark{\textcolor{teal}{\ding{51}}}% TealCheckMark
\newcommand\xmark{\textcolor{red}{\ding{55}}} % ReadCrossMark
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\newcommand\TN[1]{\TblrNote{#1}}
\begin{document}
\begin{table}[ht]
\caption {Caption title}
\centering
\begin{tblr}{colspec = {Q[l, m, wd=50mm] *{4}{Q[c, m]} Q[l, m]},
row{1} = {font=\bfseries}
}
\toprule
Title & A & B & C & D & E \\
\midrule
Some text, in some cases a little paragraph
& \cmark & \xmark & \cmark & \xmark & Ref number \\
Some text, in some cases a little paragraph
& \xmark & \xmark & \cmark & \xmark & Ref number \\
\bottomrule
\end{tblr}
\end{table}
\end{document}