使用多列的表格垂直线偏移和居中问题

使用多列的表格垂直线偏移和居中问题

我使用 tabularx 制作表格,并希望合并一些多列以合并单元格以提高可读性。但是使用多列会导致右侧垂直线略微偏移。而且文本不再居中。是我的代码有问题还是 tabularx 以某种方式与多列冲突?

在我尝试使用多列之前和之后。它只是整个表格最右侧列的一个片段。

这是有错误的 MWE 代码:

\documentclass[11pt, a4paper]{article}

% load packages------------------------------------------------------------------
\usepackage[T1]{fontenc}
\usepackage[scaled]{helvet} %Schriftart
\renewcommand{\familydefault}{\sfdefault}
\usepackage{graphicx}
\usepackage{array}
\usepackage{makecell}
\usepackage{ulem}
\usepackage[dvipsnames]{xcolor}
\definecolor{iavgreen}{RGB}{145,198,14}
\definecolor{iavred}{RGB}{206,0,55}
\definecolor{iavgrey}{RGB}{204,204,204}

% Prevent Tables from Floating
\usepackage{tabularx}
\usepackage{tocloft}
\usepackage{float}
\restylefloat{table}
\usepackage{caption}
\usepackage{multirow}
\usepackage{dblfloatfix}
\renewcommand\tabularxcolumn[1]{m{#1}}% for vertical centering text in X column
% New Columntype for Centered Columns
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcolumntype{N}{@{}m{0pt}@{}} %vertical centering, leftalign
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}} %vertical and horizontal centering
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}} %vertical centering let align and linebreak!

\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage[export]{adjustbox}
\usepackage[parfill]{parskip} %no indents
\usepackage[left=2.4cm,top=3.5cm,bottom=2.8cm,right=1.2cm,headheight=90pt]{geometry}
\restylefloat{table}
\setcounter{tocdepth}{3} %TOC depth nur 3 sections

\begin{document}

\section{Ergebnisübersicht}

\begin{small}
    \begin{tabularx}{0.85\linewidth}{|>{\hsize=.12\hsize}X >{\hsize=.62\hsize}X|>{\hsize=.26\hsize}Y|}
        \hline
        \textbf{Test} & & \textbf{Ergebnis}  \\
        \hline
        \textbf{2} & \textbf{Kalibriertest Areaview} & !@CalAVpassed@!  \\
        \hline
        \textbf{3} & \textbf{Rearview} &  \\
        \hline
        3.1 &   Kalibriertest Rearview & !@CalRVpassed@!  \\
        \hline
        3.1.1 & Kalibriertest Rearview (Kleine Kalibrierplatte) & !@CalRVSCpassed@!  \\
        \hline
        3.1.2 & Kalibriertest Rearview (Grosse Kalibrierplatte) & !@CalRVBCpassed@!  \\
        \hline
        3.1.3 & Ergebnisse der Kalibrierung (fixed values) & !@CalRVFVpassed@!  \\
        \hline
        3.1.4 & Ergebnisse der Kalibrierung (changed values) & !@CalRVCVpassed@!  \\
        \hline
        3.2 & \multicolumn{2}{X|}{Rearview - Parkbox} \\
        \hline
        3.2.1 & Statische Guidelines & !@RVPBSGpassed@!  \\
        \hline
        3.2.2 & Dynamische Guidelines & !@RVPBDGpassed@!  \\
        \hline
        3.3 & \multicolumn{2}{X|}{Rearview - LegalScreen}  \\
        \hline
        3.3.1 & Statische Guidelines & !@RVLSSGpassed@!  \\
        \hline
        3.3.2 & Dynamische Guidelines & !@RVLSDGpassed@!  \\
        \hline
        3.4 &   \multicolumn{2}{X|}{Rearview - Parallel Parking} \\
        \hline
        3.4.1 & Statische Guidelines & !@RVPPSGpassed@!  \\
        \hline
        3.4.2 & Dynamische Guidelines & !@RVPPDGpassed@!  \\
        \hline
        3.5 & \multicolumn{2}{X|}{Rearview - Trailer Coded}  \\
        \hline
        3.5.1 & Satische Guidelines & !@RVTCSGpassed@! \\
        \hline
        3.5.2 & Dynamische Guidelines & !@RVTCDGpassed@!  \\
        \hline
        3.6 & Rearview - Trailer Not Coded & !@RVTNCpassed@!  \\
        \hline
        3.7 & Rearview - Crossing Traffic & !@RVCTpassed@!  \\
        \hline
        \textbf{4} & \textbf{Frontview} &  \\
        \hline
        4.1 & \multicolumn{2}{X|}{Frontview - Parking Assist}  \\
        \hline
        4.1.1 & Statische Guidelines & !@FVPASGpassed@! \\
        \hline
        4.1.2 & Dynamische Guidelines & !@FVPADGpassed@!  \\
        \hline
        4.2 &   Frontview - Crossing Traffic & !@FVCTpassed@!  \\
        \hline
        4.3 & Frontview - Offroad & !@FVOpassed@! \\
        \hline
        \textbf{5} &    \textbf{Sideview} & !@SVpassed@!  \\
        \hline
        \textbf{6} &    \textbf{2D Birdview} & !@TWODBVpassed@!  \\
        \hline
        \textbf{7} &    \textbf{3D Birdview} & !@THREEDBVpassed@!  \\
        \hline
    \end{tabularx}
\end{small}

\end{document}

答案1

我猜你正在寻找这样的东西:

在此处输入图片描述

\documentclass[11pt, a4paper]{article}
\usepackage[left=2.4cm,top=3.5cm,bottom=2.8cm,right=1.2cm,headheight=90pt]{geometry}

% load packages------------------------------------------------------------------
\usepackage[T1]{fontenc}
\usepackage[scaled]{helvet} %Schriftart
\renewcommand{\familydefault}{\sfdefault}
\usepackage{graphicx}
\usepackage{array, makecell, tabularx}


\begin{document}
    \begin{table}[ht]
    \small
    \setcellgapes{3pt}
    \makegapedcells
\begin{tabularx}{0.85\linewidth}{|l 
                                  >{\hsize=1.3\hsize}X|
                                  >{\hsize=0.7\hsize}X|}
        \Xhline{1pt}
\textbf{Test} 
            &   & \textbf{Ergebnis}  \\
        \Xhline{0.8pt}
\textbf{2}  & \textbf{Kalibriertest Areaview}   
                                        & !@CalAVpassed@!       \\
        \hline \textbf{3}  & \multicolumn{2}{l|}{\textbf{Rearview}}            \\
        \hline
3.1         & Kalibriertest Rearview    & !@CalRVpassed@!       \\
\hline
3.1.1       & Kalibriertest Rearview (Kleine Kalibrierplatte)
                                        & !@CalRVSCpassed@!     \\
        \hline
3.1.2       & Kalibriertest Rearview (Grosse Kalibrierplatte) 
                                        & !@CalRVBCpassed@!     \\
        \hline
3.1.3       & Ergebnisse der Kalibrierung (fixed values) 
                                        & !@CalRVFVpassed@!     \\
        \hline
3.1.4       & Ergebnisse der Kalibrierung (changed values) 
                                        & !@CalRVCVpassed@!     \\
        \hline
3.2         & \multicolumn{2}{l|}{Rearview - Parkbox}           \\
        \hline
3.2.1       & Statische Guidelines      & !@RVPBSGpassed@!      \\
        \hline
3.2.2       & Dynamische Guidelines     & !@RVPBDGpassed@!      \\
        \hline
3.3         & \multicolumn{2}{l|}{Rearview - LegalScreen}       \\
        \hline
3.3.1       & Statische Guidelines      & !@RVLSSGpassed@!      \\
        \hline
3.3.2       & Dynamische Guidelines     & !@RVLSDGpassed@!      \\
        \hline
3.4         & \multicolumn{2}{l|}{Rearview - Parallel Parking}  \\
        \hline
3.4.1       & Statische Guidelines      & !@RVPPSGpassed@!      \\
        \hline
3.4.2       & Dynamische Guidelines     & !@RVPPDGpassed@!      \\
        \hline
3.5         & \multicolumn{2}{l|}{Rearview - Trailer Coded}     \\
        \hline
3.5.1       & Satische Guidelines       & !@RVTCSGpassed@!      \\
        \hline
3.5.2       & Dynamische Guidelines     & !@RVTCDGpassed@!      \\
        \hline
3.6 & Rearview - Trailer Not Coded      & !@RVTNCpassed@!       \\
        \hline
3.7 & Rearview - Crossing Traffic       & !@RVCTpassed@!        \\
        \hline
\textbf{4}  & \multicolumn{2}{l|}{\textbf{Frontview}}           \\
        \hline
4.1         & \multicolumn{2}{l|}{Frontview - Parking Assist}   \\
        \hline
4.1.1       & Statische Guidelines      & !@FVPASGpassed@!      \\
        \hline
4.1.2       & Dynamische Guidelines     & !@FVPADGpassed@!      \\
        \hline
4.2         & Frontview - Crossing Traffic
                                        & !@FVCTpassed@!        \\
        \hline
4.3         & Frontview - Offroad       & !@FVOpassed@!         \\
        \hline
\textbf{5}  &    \textbf{Sideview}      & !@SVpassed@!          \\
        \hline
\textbf{6}  &    \textbf{2D Birdview}   & !@TWODBVpassed@!      \\
        \hline
\textbf{7}  &    \textbf{3D Birdview}   & !@THREEDBVpassed@!    \\
        \Xhline{1pt}
\end{tabularx}
    \end{table}
\end{document}

答案2

您可以{NiceTabular}使用nicematrix(最新版本:2020-08-19 的 5.2) 轻松完成此操作。

\documentclass[11pt, a4paper]{article}
\usepackage[left=2.4cm,top=3.5cm,bottom=2.8cm,right=1.2cm,headheight=90pt]{geometry}

\usepackage[T1]{fontenc}
\usepackage[scaled]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{nicematrix}

\begin{document}
\begin{table}[ht]
\small
\begin{NiceTabular}{|ll|l|}[hlines]
\textbf{Test} &   & \textbf{Ergebnis}  \\
\textbf{2}   & \textbf{Kalibriertest Areaview} & !@CalAVpassed@! \\
\textbf{3}   & \multicolumn{2}{l}{\textbf{Rearview}}            \\
3.1          & Kalibriertest Rearview    & !@CalRVpassed@!      \\
3.1.1        & Kalibriertest Rearview (Kleine Kalibrierplatte) & !@CalRVSCpassed@! \\
3.1.2        & Kalibriertest Rearview (Grosse Kalibrierplatte) & !@CalRVBCpassed@! \\
3.1.3        & Ergebnisse der Kalibrierung (fixed values) & !@CalRVFVpassed@! \\
3.1.4        & Ergebnisse der Kalibrierung (changed values) & !@CalRVCVpassed@! \\
3.2          & \multicolumn{2}{l}{Rearview - Parkbox}           \\
3.2.1        & Statische Guidelines         & !@RVPBSGpassed@!  \\
3.2.2        & Dynamische Guidelines        & !@RVPBDGpassed@!  \\
3.3          & \multicolumn{2}{l}{Rearview - LegalScreen}       \\
3.3.1        & Statische Guidelines         & !@RVLSSGpassed@!  \\
3.3.2        & Dynamische Guidelines        & !@RVLSDGpassed@!  \\
3.4          & \multicolumn{2}{l}{Rearview - Parallel Parking}  \\
3.4.1        & Statische Guidelines         & !@RVPPSGpassed@!  \\
3.4.2        & Dynamische Guidelines        & !@RVPPDGpassed@!  \\
3.5          & \multicolumn{2}{l}{Rearview - Trailer Coded}     \\
3.5.1        & Satische Guidelines          & !@RVTCSGpassed@!  \\
3.5.2        & Dynamische Guidelines        & !@RVTCDGpassed@!  \\
3.6          & Rearview - Trailer Not Coded & !@RVTNCpassed@!   \\
3.7          & Rearview - Crossing Traffic  & !@RVCTpassed@!    \\
\textbf{4}   & \multicolumn{2}{l}{\textbf{Frontview}}           \\
4.1          & \multicolumn{2}{l}{Frontview - Parking Assist}   \\
4.1.1        & Statische Guidelines         & !@FVPASGpassed@!  \\
4.1.2        & Dynamische Guidelines        & !@FVPADGpassed@!  \\
4.2          & Frontview - Crossing Traffic & !@FVCTpassed@!    \\
4.3          & Frontview - Offroad          & !@FVOpassed@!     \\
\textbf{5}   & \textbf{Sideview}            & !@SVpassed@!      \\
\textbf{6}   & \textbf{2D Birdview}         & !@TWODBVpassed@!  \\
\textbf{7}   & \textbf{3D Birdview}         & !@THREEDBVpassed@!\\
\end{NiceTabular}
\end{table}
\end{document}

上述代码的输出

相关内容