2

I use tabularx for a table and wanted to incorporate some multicolumns to merge cells for readability reasons. Using multicolumns though results in a slight offset of the right vertical line. Also the text is not centered anymore. Is there a problem in my code or does tabularx conflict with multicolumn somehow?

Before and after i tried to use multicolumns. It's just a snippet of the most right column whole table.

Here is the MWE code with the error:

\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}
14
  • Welcome to TeX.SE... Please always post the MWE from \documentclass{...} to \end{document}...
    – MadyYuvi
    Aug 12 '20 at 7:09
  • The values next to \hsize should add up to the total number of X columny. Currently they add up to 1. Also, small is not an environment. How is the Y column type defined?
    – leandriis
    Aug 12 '20 at 7:14
  • Depending on the textwidth, a simple \begin{tabular}{lll} should work as well.
    – leandriis
    Aug 12 '20 at 7:17
  • It worked well before I used the multicolumn inside of the table - that's why I am wondering (just by removing multicolumn and using 2 normal columns would look like the left part of the screenshot). The hsizes worked before perfectly. Y column definition: \newcolumntype{Y}{>{\centering\arraybackslash}X}. And i need to use tabularx for my cell formatting.
    – Alex22
    Aug 12 '20 at 7:21
  • Using \begin{tabularx}{0.8\linewidth}{|>{\hsize=.36\hsize}X >{\hsize=1.86\hsize}X|>{\hsize=.78\hsize}Y|} with \hsizes that add up to 3, the code works perfectly fine.
    – leandriis
    Aug 12 '20 at 7:29
0

I guess that you looking for something like this:

enter image description here

\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}
1
  • This also works for me. Thanks alot too!
    – Alex22
    Aug 12 '20 at 8:47
0

You can do that easily with {NiceTabular} of nicematrix (the latest version : 5.2 of 2020-08-19).

\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}

Ouput of the above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.