2
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=4.00cm, bottom=3.00cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage{tabularx}

\begin{document}
\begin{tabularx}{\textwidth}{XlXlXlXlXlXl}
    {\tiny Class} & {\tiny STUDY} & {\tiny Student} & {\tiny Number} & {\tiny Exercise} & {\tiny Datum} \\
    XYZ & SJSO & A LONGER NAME & 129309 &  E01 &  \today \\
\end{tabularx}
\end{document}

I get following output: enter image description here

It doesn't look great, does it? I would love to distribute it somehow that it looks more evenly. It could look similar to something like that:

enter image description here

2 Answers 2

2

How about this?

enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage[left=2.00cm, right=2.00cm, top=4.00cm, bottom=3.00cm]{geometry}
%\usepackage{tabularx}

\begin{document}
\noindent
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lcclll @{}}
    {\tiny Class} & {\tiny STUDY} & {\tiny Student} & {\tiny Number} & {\tiny Exercise} & {\tiny Datum} \\
    XYZ & SJSO & A LONGER NAME & 129309 &  E01 &  \today \\
\end{tabular*}
\end{document}

The @{\extracolsep{\fill}} is a trick I learned from one of Mico's answers a while ago, it forces extra space but doesn't work with all X columns. I changed them to c for centre or l for left so the \extracolsep could work, you can change them to what you desire.

There are probably a lot of ways to do this, I am sure others will have valuable contributions too but this works and looks similar to your picture.

Edit: changed to tabular* as the X column was not being used (per @Mico), commented out \usepackage{tabularx} and added \noindent before the table.

2
  • 1
    +1. :-) However, since you're not using the X column type anywhere, your solution is equivalent to \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lcclll @{}} (and \end{tabular*} at the end). For the sake of code hygiene, you may want to fix the setup. You should also execute` \noindent` immediately before \begin{tabular*} (or, for that matter, \begin{tabularx}). (The fact that the OP's code is missing such a \noindent instruction isn't a reason for not providing this instruction in an answer, is it?)
    – Mico
    Oct 9, 2022 at 21:48
  • 1
    @Mico I edited your feedback into the question, I forgot \noindent as usually my tables have lots of space around them but I see I should have included it in this case! Thanks again
    – JamesT
    Oct 9, 2022 at 21:54
2
  • for good answer is missed context the use of your table
  • below are four cases how it can be formatted: one with use of the tabularx and three with use of the tabularray packages:
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[hmargin=2.00cm, vmargin={4.00cm, 3.00cm}]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage[ngerman]{babel}
\usepackage{tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{tabularray}

\begin{document}
\noindent%
    \begin{tabularx}{\textwidth}{*{2}{>{\hsize=0.8\hsize}L} >{\hsize=1.4\hsize}L
                                 *{2}{>{\hsize=0.8\hsize}L} >{\hsize=1.4\hsize}L}
{\tiny Class} & {\tiny STUDY}  & {\tiny Student} 
              & {\tiny Number} & {\tiny Exercise} & {\tiny Datum} \\
    XYZ & SJSO & A LONGER NAME & 129309 &  E01 &  \today \\
    \end{tabularx}

\vspace{3\baselineskip}
\noindent%   
    \begin{tblr}{colspec= {*{2}{X[l]} X[2,l] *{2}{X[l]} X[1.5,l]},
                 row{1} = {font=\tiny}
                 }
Class   & STUDY & Student       & Number & Exercise &  Datum    \\
XYZ     & SJSO  & A LONGER NAME & 129309 & E01      &  \today   \\
    \end{tblr}
 
\vspace{3\baselineskip}
\noindent%
    \begin{tblr}{colspec= {*{2}{X[l]} X[2,l] *{2}{X[l]} X[1.5,l]},
                 row{1} = {font=\bfseries}
                 }
Class   & STUDY & Student       & Number & Exercise &  Datum    \\
XYZ     & SJSO  & A LONGER NAME & 129309 & E01      &  \today   \\
    \end{tblr}

\vspace{3\baselineskip}
\noindent%
    \begin{tblr}{colspec= {*{2}{X[l]} X[2,l] *{2}{X[l]} X[1.5,l]},
                 row{1} = {font=\bfseries}
                 }
Class   & STUDY & Student       & Number & Exercise &  Datum    \\
    \hline{1pt}
XYZ     & SJSO  & A LONGER NAME & 129309 & E01      &  \today   \\
    \end{tblr}
   
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .