如何修改LaTeX表格首列文本方向?
解决表格首列竖排文本的排版问题
我来帮你搞定这个首列竖排的问题!看了你的代码,主要是首列的旋转文本在排版时的容器设置和命令混用有点小问题,咱们一步步调整:
第一个tblr表格的修正方案
你原来的代码里用了\parbox+\multirow+\rotatebox的组合,其实tblr(来自tabularray包)本身就支持更简洁的竖排单元格设置,而且能避免对齐错乱。修正后的代码如下:
\begin{table}[h!] \centering \caption[Transformation table]{Transformations generated by Mach et al. Y in a dark cell: highly recommended, Y in a light cell: usable, N in a dark cell: unusable \label{tab:power}} \begin{tblr}{ colspec={Q[c,wd=1.5cm,cmd=\rotatebox{90}]XXXXXX}, vlines, hlines, cells={halign=c}, column{2}={halign=l}, hspan=even, } & \SetCell[c=5]{halign=c,bg=gray,fg=white} Type of Distribution & & & & &\\ \SetCell[r=5]{bg=gray,fg=white} Type of Transformation & & Lognormal & Exponential & Gamma & Weibull \\ & Box-Cox & Y & Y & \SetCell{bg=lightgray,font=\bfseries} Y & \SetCell{bg=lightgray,font=\bfseries} Y \\ & Exponential & Y & Y & Y & Y\\ & Simple power & Y & \SetCell{bg=lightgray,font=\bfseries} Y & \SetCell{bg=lightgray,font=\bfseries} Y & \SetCell{bg=lightgray,font=\bfseries} Y \\ & Logarithmic & \SetCell{bg=lightgray,font=\bfseries} Y & Y & \SetCell{font=\bfseries} N & \SetCell{font=\bfseries} N \\ \end{tblr} \end{table}
关键修改点:
- 把首列的
colspec改成Q[c,wd=1.5cm,cmd=\rotatebox{90}]:直接用tblr的Q列类型设置宽度,并用cmd属性自动旋转单元格内的文本,不需要手动嵌套\parbox和\multirow - 移除了原来首列里的
\parbox和\multirow,简化代码的同时避免了宽度不足导致的文本截断 - 调整了首列宽度(
wd=1.5cm),保证竖排的“Type of Transformation”能完整显示
第二个tabular表格的修正方案
你的第二个表格里\parbox的宽度设置得太窄(2mm),导致“rota”文本无法正常显示,调整宽度后就能解决:
\begin{table}[H] \centering \begin{tabular}{|c|l|r|r|r|r|} \hline & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{Text} & \multicolumn{1}{|c|}{text}\\ \hline \multirow{3}{*}{\rotatebox{90}{\parbox{1cm}{\centering rota}}} & text & & & & \\ & text & & & & \\ & text & & & & \\ \hline \end{tabular} \end{table}
关键修改点:
- 把
\parbox的宽度从2mm改成1cm,给竖排文本足够的显示空间 - 给
\parbox加上\centering,让文本在竖排容器里居中对齐,视觉效果更美观
这样调整后,两个表格的首列竖排文本就能完美呈现你想要的效果啦!
内容的提问来源于stack exchange,提问作者Abbas
相关产品推荐
相关产品推荐

