3

My following MWE works in general but it returns a white space after the second column in the light grey head row. I can avoid this if I don't apply the \mcxcommand on the column content ("Copolymer (Versuchsnummer)") but then I can't perform a \linebreakor \par anymore. The \parcommand works within the \mcxcommand but results in producing a white space between the 2nd and the 3rd cell of the first row (see attached picture) since the content in the second column is too wide.

Can help me adjusting the width of the second column to fit the content's width? But it is very important to me that columns 3-6 keep the same width while the table still fits the line width!

Thanks a lot Cheers Benson_G

enter image description here

\usepackage[onehalfspacing]{setspace} %Zeilenabstand
\usepackage[hmargin={3cm,2cm},vmargin=2cm, includehead]{geometry}%Maße für die wissenschaftliche Arbeit
\usepackage[parfill]{parskip} %Bessere Seitenumbrüche
\usepackage[T1]{fontenc} %Silbentrennung
\usepackage[german]{babel} %Sprachanpassungen
% \usepackage[utf8]{inputenc} %Direkte Angabe von Umlauten möglich 
\usepackage{csquotes}
\usepackage{graphicx} %Einfügen von Bildern
% \usepackage{tabularx} %Tabellen
% \usepackage{booktabs} %Weitere Möglichkeiten für Tabellen
\usepackage{here} %Lage von Tabellen und Bildern 
\usepackage{physics}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage{textgreek}
\usepackage{textcomp}
\usepackage{amssymb}
% \usepackage[labelformat=simple]{subcaption}
\usepackage{float}
\usepackage{pdfpages}
\usepackage{lmodern} 
\usepackage{enumitem}
\usepackage{parskip}
\usepackage[hyphens]{url} % be sure to specify the option 'hyphens'
% \usepackage[pdftex,bookmarksnumbered,hidelinks,breaklinks]{hyperref}
% \usepackage[superscript]{cite}

% ======SCHRIFTART=================================

% Schriftart Helvetica \usepackage[scaled]{helvet} \renewcommand\familydefault{\sfdefault}

% ===================================================

\usepackage[per-mode = reciprocal, output-decimal-marker={,}, exponent-product = {\cdot}]{siunitx} %Si-Einheiten

\usepackage[headsepline,automark, draft = false]{scrlayer-scrpage} %Für Kopf und Fußzeile und Seitenzahlen \clearpairofpagestyles \ihead{\headmark} \rohead{\pagemark} % \cfoot{\pagemark} \addtokomafont{pageheadfoot}{\upshape} \KOMAoptions{onpsinit={\linespread{1}\selectfont}}

%=======TABELLEN=====================================

\usepackage[column=O]{cellspace} % <-- new \setlength\cellspacetoplimit{2pt} \setlength\cellspacebottomlimit{2pt} \addparagraphcolumntypes{X} \usepackage{booktabs, tabularx}
\newcommand\mcx[1]{\multicolumn{1}{>{\centering\arraybackslash}X}{#1}}

\usepackage[version=4]{mhchem} % newest version \usepackage{siunitx}% instead of units, which is deprecate \usepackage[labelsep = period, skip=1ex, format=plain, font=small, labelfont=bf, justification = justified]{caption} % new %\usepackage[labelformat=simple]{subcaption} \usepackage{colortbl} % changed, instead of "color" and "colortbl" \definecolor{hellgrau}{rgb}{0.90,0.90,0.90} \definecolor{ExpBlau}{rgb}{0.11,0.19,0.46}

%===================================================== %=====================================================

\begin{document}

\renewcommand{\tablename}{Tabelle} \renewcommand{\figurename}{Abbildung} \captionsetup[table]{justification = raggedright, font=normal, singlelinecheck=false}

\begin{table}[htb!] \centering \footnotesize \setlength\belowcaptionskip{5 pt} \renewcommand\tabularxcolumn[1]{m{#1}} \caption{\textbf{Molekulare Eigenschaften der P(EO-\textit{co}-EPB)-Copolymere}} \begin{tabularx}{\linewidth}{llcccc} \rowcolor{hellgrau} \vspace{0.2cm} Probe
& \mcx{Copolymer \par (Versuchsnummer)} & \mcx{$\textit{M}\text{n, NMR}$\par (g mol$^{\text{-1}}$)} & \mcx{mol% EPB$^{\textcolor{ExpBlau}c}$} & \mcx{$\textit{M}\text{n, GPC}$\par (g mol$^{\text{-1}}$)}
& \mcx{\textit{Đ}} \

        \hspace{3mm}    1                             &amp;    P(EO$_\text{141}$-\textit{co}-EPB$_\text{y}$)    &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    2                             &amp;    P(EO$_\text{58}$-\textit{co}-EPB$_\text{y}$)     &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    3                             &amp;    P(EO$_\text{x}$-\textit{co}-EPB$_\text{y}$)      &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    4                             &amp;    P(EO$_\text{x}$-\textit{co}-EPB$_\text{y}$)      &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    5                             &amp;    P(EO$_\text{x}$-\textit{co}-EPB$_\text{y}$)      &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    6                             &amp;    P(EO$_\text{x}$-\textit{co}-EPB$_\text{y}$)      &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    7                             &amp;    P(EO$_\text{x}$-\textit{co}-EPB$_\text{y}$)      &amp;   &amp;   &amp;   &amp;   \\
        \hspace{3mm}    8                             &amp;    P(EO$_\text{x}$-\textit{co}-EPB$_\text{y}$)      &amp;   &amp;   &amp;   &amp;   \\
\end{tabularx}
\vspace{0.6 \baselineskip} \\
\raggedright
$^{\textcolor{ExpBlau}a}$ Molekulargewicht aus $^\text{1}$H-NMR-Spektrum berechnet, $^{\textcolor{ExpBlau}b}$Molekulargewicht aus GPC, .

\label{tab:Copo}% \vspace{-1.8 \baselineskip} \end{table} \end{document}

  • never use tabularx without a X column, just use tabular here let the columns be natural width then the second column will be wide enough for its heading. – David Carlisle Nov 26 '20 at 11:58
  • I would like to keep sticking to tabularxbecause I want to implement the overhang parameter of columncolor later as it's explained in the thread with its link attached. Since I've noticed that you have also commented on the thread I am referring to with the same piece of advice I assume you probably cannot help me with my problem.(https://tex.stackexchange.com/a/301036/229635) – Benson_G Nov 26 '20 at 12:36
  • 1
    the overhang parameter comes from colortbl not tabularx and would work with a normal tabular. tabularx simply can not work properly without an X column so if you stick to tabularx use X columns in the table preamble and force the hsize of column 2 to be wide enough for the heading with >{\hsize=1.5\hsize} or whatever is needed but really this is my code and I promise you tabularx is not helping you here. – David Carlisle Nov 26 '20 at 12:38

1 Answers1

1

enter image description here

\documentclass[a4paper,10pt,
               enabledeprecatedfontcommands]{scrartcl} %Art des Dokuments, Schriftgröße etc.
\usepackage[hmargin={3cm,2cm},vmargin=2cm,
            includehead]{geometry}%Maße für die wissenschaftliche Arbeit
\usepackage{lmodern}
\usepackage[T1]{fontenc} %Silbentrennung
\usepackage[english]{babel} %Sprachanpassungen

\usepackage{booktabs, tabularx} % Tabellen \newcolumntype{C}{>{\centering\arraybackslash}X} \newcommand\MC[1]{\begin{tabular}{@{} c @{}} #1 \end{tabular}} %\addparagraphcolumntypes{C}

\usepackage[version=4]{mhchem} % newest version \usepackage[per-mode = reciprocal, output-decimal-marker={,}, exponent-product = {\cdot}]{siunitx} %Si-Einheiten \usepackage[skip=1ex]{caption} % new \captionsetup[table]{justification = raggedright, font=bf, singlelinecheck=false} \usepackage[table]{xcolor} % changed, instead of "color" and "colortbl" \definecolor{ExpBlau}{rgb}{0.11,0.19,0.46} \definecolor{hellgrau}{rgb}{0.90,0.90,0.90}

\begin{document} \begin{table}[ht] \centering \footnotesize \renewcommand\tabularxcolumn[1]{m{#1}} \caption{Molekulare Eigenschaften der P(EO-\textit{co}-EPB)-Copolymere} \label{tab:Copo}% \begin{tabularx}{\linewidth}{clCCCC} \rowcolor{hellgrau} Probe & \MC{Copolymer\ (Versuchsnummer)} & $M_\text{n, NMR}$ (\si{\gram\per\mol}) & mol% EPB$^{\textcolor{ExpBlau}c}$ & $M_\text{n, GPC}$ (\si{\gram\per\mol}) & \textit{Đ} \

1 & P(EO${141}$-\textit{co}-EPB$\text{y}$) & & & & \ 2 & P(EO${58}$-\textit{co}-EPB$\text{y}$) & & & & \ 3 & P(EO$\text{x}$-\textit{co}-EPB$\text{y}$) & & & & \ 4 & P(EO$\text{x}$-\textit{co}-EPB$\text{y}$) & & & & \ 5 & P(EO$\text{x}$-\textit{co}-EPB$\text{y}$) & & & & \ 6 & P(EO$\text{x}$-\textit{co}-EPB$\text{y}$) & & & & \ 7 & P(EO$\text{x}$-\textit{co}-EPB$\text{y}$) & & & & \ 8 & P(EO$\text{x}$-\textit{co}-EPB$\text{y}$) & & & &
\end{tabularx} \vspace{0.6 \baselineskip} \ \raggedright $^{\textcolor{ExpBlau}a}$ Molekulargewicht aus $^\text{1}$H-NMR-Spektrum berechnet, $^{\textcolor{ExpBlau}b}$Molekulargewicht aus GPC. \end{table} \end{document}

Note:

  • above MWE is based on my answer on your previous question, but it is adopted to your new problem: width of the second column, which is apparently wider than other X columns in table (hidden in \mcx)
  • you should carefully read my previous answer, there is comment about use of \mcx command, you should not use them in this table but for column type in the last four columns use modification of X column:
\newcolumntype{C}{>{\centering\arraybackslash}X}
  • above change has sense, if this column not contain numbers, which you like to align at decimal point (comma)
  • for the second column you can define new command, for example \MC which enable to write cells' contents in l (c, r) columns in more lines:
\newcommand\MC[1]{\begin{tabular}{@{} c @{}} #1 \end{tabular}}
  • for use of this command see MWE above.

  • it is not entirely clear, if you really need tabularx (content of table is unknown)

  • also it is possible that the proposed solution in the previous answer is more appropriate by following the \MC command in the second column

Off-topic: Please, please always provide only MWE (Minimal Working Example). In your preamble is easy to lost. Also see all changes made in received answer, Regardless that they not all on-topic, they suggest some improvements to your code, which make it more consistent, shorter etc.

Zarko
  • 296,517
  • Is there a way to solve the problem with the white thin vertical lines between the color filled cells with this code? – Benson_G Nov 26 '20 at 12:47
  • Can you explain to me what this code line does in detail? I want to understand the syntax. \newcommand\MC[1]{\begin{tabular}{@{} c @{}} #1 \end{tabular}} – Benson_G Nov 26 '20 at 12:49
  • @Benson_G, see added explanation. – Zarko Nov 26 '20 at 13:02
  • May I ask this question again: Is there a way to solve the problem with the white thin vertical lines between the color filled cells with this code? – Benson_G Nov 26 '20 at 13:18
  • \newcommand\MC[1]{\begin{tabular}{@{} c @{}} #1 \end{tabular}}how can I center the content within this command but keep l for the rest of the column? – Benson_G Nov 26 '20 at 15:35