我有这个MWE:
\documentclass[12pt,landscape,a4paper]{article}
\usepackage{multirow}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\usepackage{ragged2e}
\newcommand*\fixalign[2][]{\begin{tabular}{@{}S[#1]@{}}#2\end{tabular}}
\begin{document}
\begin{longtable}{p{4cm}ccS[table-format=1.1]}
\multirow{2}{4cm}{\strut \Centering Název} &
\multicolumn{2}{c}{\Centering Premiéra} &
\multirow{2}{0.8cm}{\Centering Min. doba} \\
&\Centering Svět & \Centering ČR & \\
\Centering Kazatel Kalašnikov & 1.2. & 3.4. & 5.8\\
\Centering Musíme si promluvit o Kevinovi &
\multirow{2}{*}{1.6.} &
\multirow{2}{*}{5.4} &
\multirow{2}{*}{\fixalign[table-format=1.1]{2.8}}\\
\end{longtable}
\end{document}
编译后的结果如下:
我希望 5.8 和 2.8 对齐。我认为我需要定义列以具有一定的宽度,然后才使用 siunitx,但我不确定如何做到这一点。(我的实际表格要大得多,也稍微复杂一些。)
答案1
像往常一样,multirow
这不是答案;我删除了不必要的包,如果你真的需要它们,就把它们加回来。
\documentclass[12pt,a4paper]{article}
% the following three should be first
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{makecell}
\usepackage{ragged2e}
\usepackage{longtable}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\begin{longtable}{
>{\Centering}m{4cm}
S[table-format=1.1]
S[table-format=1.1]
S[table-format=1.1]
}
Název & \multicolumn{2}{c}{Premiéra} & {Min.} \\
& {Svět} & {ČR} & {deba} \\
Kazatel Kalašnikov & 1.2 & 3.4 & 5.8\\
Musíme si promluvit o Kevinovi & 1.6 & 5.4 & 2.8 \\
\end{longtable}
\end{document}
答案2
无需 s 的快速解决方案\newcommand
:
\documentclass[12pt,landscape,a4paper]{article}
\usepackage{multirow}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{hyphenat}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\usepackage{ragged2e}
\begin{document}
\begin{longtable}{p{4cm}ccS[table-format=1.1]}
\multirow{2}{4cm}{\strut \Centering Název} &\multicolumn{2}{c}{\Centering Premiéra} & \multirow{2}{0.8cm}{\Centering Min. doba} \\
&\Centering Svět & \Centering ČR & \\
\Centering Kazatel Kalašnikov & 1.2 & 3.4 & \multirow{1}{*}{5.8}\\
\Centering Musíme si promluvit o Kevinovi & \multirow{2}{*}{1.6} & \multirow{2}{*}{5.4} & \multirow{2}{*}{2.8}\\
\end{longtable}
\end{document}