当我X
输入列说明符时,如何定义列格式?如何获得居中对齐?目前我正在输入\centering
,但这不是一个合适的解决方案。
这是我的代码:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\begin{document}
\begin{table}[t]
\caption{Case studies}
\centering
\begin{tabularx}{\textwidth}{p{4cm}*{5}{X}}
\toprule
\centering Nature of unreliability & \centering Sender SST & \centering Receiver SST & \centering Implementation SST & Retransmission Bound \\
\midrule
Noisy (Single fixed error message) & DSST & DSST & DSST & Unbounded \\
\bottomrule
\end{tabularx}
\label{case-studies}
\end{table}
\end{document}
答案1
我的回答到如何创建带有文本“raggedright/centered/raggedleft”的固定宽度表格列?也可以以稍微修改的形式应用于X
列。(请注意,省略\let\newline\\
将导致文本未正确居中。)
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}
\begin{document}
\begin{tabularx}{\linewidth}{| c | c | Z |}
Abc & Bcd & Cde \\
Abc & Bcd & A long cell with text that is centered \newline
and allows manual line breaks \\
\end{tabularx}
\end{document}