我有一张如下所示的表格。
\documentclass{article}
\usepackage{graphicx}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{table}[!ht]
\centering
\begin{tabular}{| c | c | c |}
\hline
1 & 2 & 3\\ \hline
\rot{\textbf{1st column}} & \rot{\textbf{2nd column}} & \rot{\textbf{3rd column}} \\ \hline
\end{tabular}
\end{table}
\end{document}
我希望通过减少填充来调整列宽。我试过
\begin{tabular}{| p{0.1cm} | c | c |}
但是,它只会删除第一列右侧的空白,并保留其左侧的空白。
答案1
要更改 LaTeX 在每列左侧和右侧插入的垂直空白量,请更改长度参数\tabcolsep
。其默认值为;可以通过或6pt
进行更改。在下面的示例中,第二个表格的值为。\setlength
\addtolength
1.5pt
\tabcolsep
\documentclass{article}
\usepackage{graphicx}
\newcommand*\rot[1]{\rotatebox{90}{#1}}
\begin{document}
\begin{table}[!ht]
\centering
\begin{tabular}{| c | c | c |}
\hline
1 & 2 & 3\\ \hline
\rot{\textbf{1st column}} & \rot{\textbf{2nd column\ }} & \rot{\textbf{3rd column}} \\ \hline
\end{tabular}
\qquad % get some separation between the two tabulars
\setlength\tabcolsep{1.5pt} % default value: 6pt
\begin{tabular}{| c | c | c |}
\hline
1 & 2 & 3\\ \hline
\rot{\textbf{1st column}} & \rot{\textbf{2nd column\ }} & \rot{\textbf{3rd column}} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
这就是你要找的吗?
\documentclass{article}
\usepackage{graphicx}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{table}[!ht]
\centering
\begin{tabular}{|@{\hskip3pt}c@{\hskip3pt}| c |@{\hskip3pt}c@{\hskip3pt}|}
\hline
1 & 2 & 3\\ \hline
\rot{\textbf{1st column}} & \rot{\textbf{2nd column}} & \rot{\textbf{3rd column}} \\ \hline
\end{tabular}
\end{table}
\end{document}
@{}
插入位置的距离设置为零\tabcolsep
。如果您希望在此处相邻列之间的间距不同,那么您可以根据 自己的意愿在本地@{<distance>}
选择位置来确定它。<width>
附录
如今,当该tabularray
软件包(版本 2021P)可用时,人们可以考虑以下解决方案:
\documentclass{article}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{tabularray}
\begin{document}
\begin{table}[!ht]
\centering
\setlength\rotheadsize{6em}
\begin{tblr}{hlines, vlines,
colspec = {ccc},
% colsep = 6pt, % <--- default tabcolsep
row{2} = {cmd=\rotcell,font=\bfseries, rowsep=0pt}
}
1 & 2 & 3 \\
1st column & 2nd column & 3rd column \\
\end{tblr}
\qquad
\begin{tblr}{hlines, vlines,
colspec = {ccc},
colsep = 2pt, % <--- tabcolsep
row{2} = {cmd=\rotcell,font=\bfseries, rowsep=0pt}
}
1 & 2 & 3 \\
1st column & 2nd column & 3rd column \\
\end{tblr}
\qquad
\begin{tblr}{hlines, vlines,
colspec = {ccc},
colsep = 0pt, % <--- tabcolsep
row{2} = {cmd=\rotcell,font=\bfseries, rowsep=0pt}
}
1 & 2 & 3 \\
1st column & 2nd column & 3rd column \\
\end{tblr}
\end{table}
\end{document}