0

Can some help me making the table coded in this Thread https://tex.stackexchange.com/a/301036/229635 fit the line width?

As a MWE I copied the code from the Thread I attached as a link.

Thanks a lot, Cheers Benson_G

enter image description here

\documentclass[a4paper,12pt, enabledeprecatedfontcommands, toc = sectionentrywithdots]{scrartcl} %Art des Dokuments, Schriftgröße etc. , idxtotoc, bibtotoc,
\usepackage[onehalfspacing]{setspace} %Zeilenabstand
\usepackage[hmargin={3cm,2cm},vmargin=2cm, includehead]{geometry}%Maße für die wissenschaftliche Arbeit
\usepackage[scaled=0.9]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{hhline}
\usepackage{color}
\usepackage{colortbl}
 \definecolor{gr}{RGB}{240,240,240}
\usepackage{tabularx}
\usepackage{babel}

\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}


\begin{document}

\noindent
\begin{tabularx}{\textwidth}{XXXX}
    \hhline{----}
    \multicolumn{1}{>{\centering\columncolor{gr}}m{.1\textwidth}} {Here's a box\\ Score} 
            & \multicolumn{1}{>{\centering\columncolor{gr}}m{.3\textwidth}}{Here's a box\\ Score}
                        & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0pt\relax]}m{.3\textwidth}}{Another Box\\ with two Rows} %
                                    & \multicolumn{1}{>{\centering\columncolor{gr}[\tabcolsep]}m{.3\textwidth}|}{Student's\\ Proficiency Level}
    \tabularnewline%
    \hline
    Science     & 28    & 26 or above     & Proficient\tabularnewline
    \hline
  \end{tabularx}

\end{document} 
  • Did you already try to replace {11cm} with {\textwidth}? – leandriis Nov 26 '20 at 14:13
  • @leandriis yes I did. It didn't work. – Benson_G Nov 26 '20 at 14:28
  • What exactly does "it does not work" mean? Do you get a different output than the expected or an error message? Please clarify. – leandriis Nov 26 '20 at 15:37
  • I just updated my MWE and attached a picture of the output. – Benson_G Nov 26 '20 at 15:39
  • Add \noindent right before \begin{tabularx}. Also, it does not really make sense to use tabularx without any X type column. In the previous version of your question, there was an X type column present. Your table currently is wider than the textwidth, since you did not take into account the value of \tabcosep when calculating the column widths. – leandriis Nov 26 '20 at 15:40
0

Here is a first rough version of your table that now fits into the textwidth.

enter image description here

\documentclass[a4paper,12pt, toc = sectionentrywithdots]{scrartcl}
\usepackage[onehalfspacing]{setspace}
\usepackage[hmargin={3cm,2cm},vmargin=2cm, includehead]{geometry}
\usepackage[scaled=0.9]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{hhline}
%\usepackage{color}
%\usepackage{colortbl}
\usepackage[table]{xcolor} % replaces above two lines
 \definecolor{gr}{RGB}{240,240,240}
\usepackage{tabularx}
\usepackage{babel}

\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{.1\textwidth}YYY}
        \hhline{----}
        \multicolumn{1}{>{\centering\columncolor{gr}}m{.1\textwidth}} {Here's a box\\ Score} 
                & \multicolumn{1}{>{\centering\columncolor{gr}}X}{Here's a box\\ Score}
                            & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0pt\relax]}X}{Another Box\\ with two Rows} %
                                        & \multicolumn{1}{>{\centering\columncolor{gr}[\tabcolsep]}X|}{Student's\\ Proficiency Level}
        \tabularnewline%
        \hline
        Science     & 28    & 26 or above     & Proficient\tabularnewline
        \hline
\end{tabularx}
    
\end{document} 

With the help of cellspace:

enter image description here

\documentclass[a4paper,12pt, toc = sectionentrywithdots]{scrartcl}
\usepackage[onehalfspacing]{setspace}
\usepackage[hmargin={3cm,2cm},vmargin=2cm, includehead]{geometry}
\usepackage[scaled=0.9]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{hhline}
%\usepackage{color}
%\usepackage{colortbl}
\usepackage[table]{xcolor} % replaces above two lines
 \definecolor{gr}{RGB}{240,240,240}
\usepackage{tabularx}
\usepackage{babel}

\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\usepackage[column=0]{cellspace}
\setlength{\cellspacetoplimit}{20pt}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\addparagraphcolumntypes{X}
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{.1\textwidth}YYY}
        \hhline{----}
        \multicolumn{1}{>{\centering\columncolor{gr}}0{m{.1\textwidth}}} {Here's a box\\ Score} 
                & \multicolumn{1}{>{\centering\columncolor{gr}}0{X}}{Here's a box\\ Score}
                            & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0pt\relax]}0{X}}{Another Box\\ with two Rows} %
                                        & \multicolumn{1}{>{\centering\columncolor{gr}[\tabcolsep]}0{X}|}{Student's\\ Proficiency Level}
        \tabularnewline%
        \hline
        Science     & 28    & 26 or above     & Proficient\tabularnewline
        \hline
\end{tabularx}
    
\end{document} 
  • this is working pretty well. Thanks a lot! :) – Benson_G Nov 27 '20 at 6:54
  • Two last questions: Is there a way to 1. increase the row height of only the first row and 2. to add some vertical space only between the first and the second row? – Benson_G Nov 27 '20 at 7:03
  • You could use the cellspace package. I have just updated my answer to include a second example that demostrates the use of the before mentioned package. I used exaggerated values just to show the effect more clearly. – leandriis Nov 27 '20 at 7:55
0

Hey guys and @leandriis,

I could manage to solve my problems by myself.

Here is what the final code looks like....just in case you are interested: It includes a way:

  1. to solve the prob with white thin vertical lines between the color filled cells by using @leandriis code in this thread above

  2. to only change the row height of the first row by using

\usepackage{stackengine} % Package to change row height
\newcommand\xrowht[2][0]{\addstackgap[.5\dimexpr#2\relax]{\vphantom{#1}}} 

in the preamble and \xrowht{10pt}within the multicolumn curly brackets for text. (How to specify the row height in LaTeX table?)

  1. to add vertical space only between two specific cells with \addlinespace[0.2cm] right after the command for a new tabular line (Inserting a small vertical space in a table)

enter image description here

\documentclass[a4paper,12pt, enabledeprecatedfontcommands, toc = sectionentrywithdots]{scrartcl} %Art des Dokuments, Schriftgröße etc. , idxtotoc, bibtotoc,
\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{ragged2e} %für Blocksatzschalter \justifying
% \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{booktabs, tabularx}  

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\usepackage{stackengine} % Für Zeilenabstand
\newcommand\xrowht[2][0]{\addstackgap[.5\dimexpr#2\relax]{\vphantom{#1}}}

\renewcommand\tabularxcolumn[1]{m{#1}}

\usepackage[version=4]{mhchem}  % newest version
\usepackage{siunitx}% instead of units, which is deprecate
\sisetup{detect-weight,detect-mode}%Si-Einheiten
\usepackage[labelsep = period, skip=1ex, format=plain, font=small, labelfont=bf, justification = justified]{caption}     % new
%\usepackage[labelformat=simple]{subcaption}
\usepackage{colortbl}
\definecolor{ExpBlau}{rgb}{0.11,0.19,0.46}
\definecolor{gr}{rgb}{0.90,0.90,0.90}

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

\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}
  \caption{\textbf{Molekulare Eigenschaften der P(EO-\textit{co}-EPB)-Copolymere$^{\textcolor{ExpBlau}a}$}}
\noindent
\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{.04\textwidth}>{\centering\arraybackslash}m{.185\textwidth}YYYY}
    
        \multicolumn{1}{>{\centering\columncolor{gr}}m{.04\textwidth}} {\xrowht{10pt}Nr.} 
                    & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0.3pt\relax]}m{.185\textwidth}} {\xrowht{10pt}Copolymer} 
                            & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0.3pt\relax]}X}{\xrowht{10pt}$\textit{M}_\text{n, NMR}$ (\si{\gram\per\mole})}
                                        & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0.3pt\relax]}X}{\xrowht{10pt} mol\% EPB$^{\textcolor{ExpBlau}c}$} %
                                                    & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 0.3pt\relax]}X}{\xrowht{10pt}$\textit{M}_\text{n, GPC}$ (\si{\gram\per\mole})} %
                                                                & \multicolumn{1}{>{\centering\columncolor{gr}[\tabcolsep]}X}{\xrowht{10pt} \textit{Đ}}
        \tabularnewline\addlinespace[0.2cm]  
                                                                                                                                                          %  SASSK
                            1                             &    ThatsALongWord    &  xxxx  &  x,x  &  xxxx  &  x,xx \tabularnewline      %   113
                            2                             &    ThatsALongWord    &  xxxx  &  x,x  &  xxxx  &  x,xx \tabularnewline      %   114
           \hspace{ 0.5mm}  3$^{\textcolor{ExpBlau}b}$    &    ThatsALongWord    &  xxxx  &  x,x  &  xxxx  &  x,xx \tabularnewline      %   101
                            4                             &    ThatsALongWord    &  xxxx  &  x,x  &  xxxx  &  x,xx \tabularnewline      %   111
                            5                             &    ThatsALongWord    &  xxxx  &  x,x  &  xxxx  &  x,xx \tabularnewline      %   105
                            6                             &    ThatsALongWord    &  xxxx  &  x,x  &  xxxx  &  x,xx \tabularnewline      %   112
\end{tabularx}
    \vspace{0.6 \baselineskip} \\
    \justifying
    $^{\textcolor{ExpBlau}a}$ Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
  \label{tab:Copo}
\end{table}

\end{document}

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.