我想创建一个带有垂直标题的表格,并在标题上方添加额外的分类。但我不知道如何固定表格的大小。有人能帮我吗?我也总是使用 p{\textwidth} 来调整表格的大小以适合我的页面。这不是一个实用的解决方案。但是,这是我发现的唯一一种适合页边距的表格形式。如果有人对此也有评论。我很乐意得到一些提示。
\begin{table}[H]
\centering
\begin{tabular}{p{.15\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}p{.05\textwidth}}
\toprule
\textbf{Sensitivity}
& \multicolumn{1}{c}{\textbf{Electricity}}
& \multicolumn{4}{c}{\textbf{Fuels}}
& \multicolumn{2}{c}{\textbf{Transport}}
& \multicolumn{2}{c}{\textbf{Othe parameters}} \\ \hline
&
\turnbox{90}{Ren.Expansion [GW]} &
\turnbox{90}{H$_2$}&
\turnbox{90}{CH$_4$}&
\turnbox{90}{NH$_3$}&
\turnbox{90}{CH$_3$OH}&
\turnbox{90}{BEV private [Mio]}&
\turnbox{90}{Public Buses [Mio]}&
\turnbox{90}{CO$_2$ Budget [Mton]}&
\turnbox{90}{WACC [\%]}\\
\midrule
Base & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
A & 5 & 1 & 2 & 3 & 4 & \ 1 & 2 & 10 & 7 \\
B & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
C & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
D & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
E & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
\bottomrule
\end{tabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
答案1
像这样吗?
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{graphicx,booktabs,mhchem,makecell,array}
\let\turnbox\rotatebox % ??
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{@{} l *{7}{c} wc{.1\textwidth} c @{}}
\toprule
\textbf{Sensitivity} &
\multicolumn{1}{c}{\textbf{\makecell{Elec-\\tricity}}} &
\multicolumn{4}{c}{\textbf{Fuels}} &
\multicolumn{2}{c}{\textbf{\makecell{Trans-\\port}}} &
\multicolumn{2}{c}{\textbf{\makecell{Other\\ parameters}}} \\
& [GW] & & & & & [Mio] & [Mio] & [Mton] & [\%] \\
\cmidrule(lr){2-2} \cmidrule(lr){3-6}
\cmidrule(lr){7-8} \cmidrule(l){9-10}
&
\turnbox{90}{Ren.\ Expansion} &
%\turnbox{90}{Fuels}&
\turnbox{90}{\ce{H2}} & %liquid and gas??
\turnbox{90}{\ce{CH4}} & %liquid and gas??
\turnbox{90}{\ce{NH3}} &
\turnbox{90}{\ce{CH3OH}}&
%\turnbox{90}{Transport}&
\turnbox{90}{BEV private}&
\turnbox{90}{Public Buses}&
%\turnbox{90}{Other parameters}&
\turnbox{90}{\ce{CO2} Budget}&
\turnbox{90}{WACC}\\
\midrule
Base & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
R1.7 & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
G-PP & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
R-E & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
T-E & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
BEV-E & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
\bottomrule
\end{tabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
答案2
使用{NiceTabular}
。nicematrix
您有一个内置命令\rotate
,使用\RowStyle{\rotate}
,该命令将应用于整行。
\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage[version=4]{mhchem}
\begin{document}
\begin{table}[ht]
\centering
\begin{NiceTabular}{@{}l*{9}{w{c}{7mm}}@{}}
\toprule
\RowStyle{\bfseries}
Sensitivity
& Elec.
& \Block{1-4}{Fuels}
& & & & \Block{1-2}{Transport}
& & \Block{1-2}{Other\\ parameters}
& \\
\cmidrule{2-2}
\cmidrule(rl){3-6}
\cmidrule{7-8}
\cmidrule(l){9-10}
\RowStyle{\rotate}
& \Block{}{Ren. Expansion\\ [GW]}
& \ce{H2}
& \ce{CH4}
& \ce{NH3}
& \ce{CH3OH}
& BEV private [Mio]
& Public Buses [Mio]
& \ce{CO2} Budget [Mton]
& WACC [\%] \\
\midrule
Base
& 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
A & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
B & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
C & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
D & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
E & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
\bottomrule
\end{NiceTabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
答案3
使用rotating
、makecell
和tabularray
用于表格和mhchem
化学公式的包:
\documentclass{article}
\usepackage{rotating}
\usepackage{makecell}
\renewcommand\theadfont{}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage[version=4]{mhchem}
\begin{document}
\begin{table}[ht]
\centering
\settowidth\rotheadsize{Ren. Expansion}
\begin{tblr}{colsep = 3pt,
colspec = {@{} l *{9}{Q[c,wd=3em]} @{}},
row{1} = {font=\small\bfseries, m},
row{2} = {cmd=\rothead},
hspan=minimal
}
\toprule
Sensitivity
& Elec\-tricity
& \SetCell[c=4]{c} Fuels
& & & & \SetCell[c=2]{c} Transport
& & \SetCell[c=2]{c} {Other\\ parameters}
& \\
\cmidrule[lr]{2-2}
\cmidrule[lr]{3-6}
\cmidrule[lr]{7-8}
\cmidrule[l]{9-10}
& Ren. Expansion [GW]
& \ce{H2}
& \ce{CH4}
& \ce{NH3}
& \ce{CH3OH}
& BEV private [Mio]
& Public Buses [Mio]
& \ce{CO2} Budget [Mton]
& WACC [\%] \\
\midrule
Base
& 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
A & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
B & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
C & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
D & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
E & 5 & 1 & 2 & 3 & 4 & 1 & 2 & 10 & 7 \\
\bottomrule
\end{tblr}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}