0

I'm trying to create a new table in which the text of the first column begins exactly on the left margin, and the text on the last column ends at exactly the right margin.

Additionally, I also want the first two columns to be very close together and the last two columns to be close together as well, with maximal space in between.

Here's what I have so far, which is very close, but the first column isn't exactly in the first margin, and the last column isn't exactly at the right margin either:

\documentclass[letterpaper,9pt]{article}
\usepackage[margin=1in,letterpaper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\begin{center}
    \newcolumntype{R}{>{\raggedleft\arraybackslash}X}%
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}%
    \begin{tabularx}{\textwidth}{ r l R L }
        \textbf{High Level Languages}   & Python, Mathematica              & 
        \textbf{Statistical Languages}  & Stan                             \\
        \textbf{Low Level Languages}    & C, C\texttt{++}, CUDA            & 
        \textbf{Shells}                 & Zsh, Bash                        \\
    \end{tabularx}
\end{center}

\noindent
\lipsum[1]

\end{document}

And here's a rendered version of the previous document:

And here is how I would like it to look like (done manually on photo editing software with red lines to emphasize the desired location):

I would also like to avoid line wrapping at all cost, which seems to be something that happens even thought there is still enough space between columns, and as a bonus point possibly adding a long row at the bottom that spanned across all columns, although I think this is fairly simple and a matter of creating a multiline environment, but I'm saving it for later in hopes of being able to solve this problem first.

2
  • { @{} r l R L @{} } Dec 13, 2022 at 16:46
  • 1
    "I would also like to avoid line wrapping at all cost," you are using p columns for colums 3 and 4 so explicitly for line breaking. They are the same width so if 3 is wide, so is 4. I suspect you really want rl not RL so the columns are single line and natural width Dec 13, 2022 at 16:51

3 Answers 3

3
\documentclass[letterpaper,9pt]{article}
\usepackage[margin=1in,letterpaper]{geometry}
\usepackage[utf8]{inputenc}

\usepackage{lipsum}

\begin{document}
\setlength\tabcolsep{2pt} % half the space between column 1 and 2 and
                          % between 3 and 4
\noindent
\begin{tabular*}{\textwidth}{@{} r l @{\extracolsep{\fill}} r@{\extracolsep{2\tabcolsep}} l@{} }
    \textbf{High Level Languages}   & Python, Mathematica              & 
    \textbf{Statistical Languages}  & Stan                             \\
    \textbf{Low Level Languages}    & C, C\texttt{++}, CUDA            & 
    \textbf{Shells}                 & Zsh, Bash                        \\
\end{tabular*}

\lipsum[1]

\end{document}

enter image description here

2
  • yes actually your extracolsep is more finessed than mine, I'll delete:-) Dec 13, 2022 at 16:59
  • Your solution is probably the simplest provided here, and it works. Although the syntax is rather cryptic, it works as expected, even when changing the spacing between the bold and non-bold text, given by \tabcolsep. Dec 13, 2022 at 19:45
1

Like this:

enter image description here

(red lines indicate page layout)

\documentclass[letterpaper,9pt]{article}
\usepackage[margin=1in,letterpaper]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\begin{center}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}%
\setlength\tabcolsep{3pt}   % if you like to reduce spaces between columns
                            % default size is 6pt
    \begin{tabularx}{\textwidth}{@{} >{\bfseries}r L >{\bfseries}r l @{}}
                            % @{} remove \tabcolsep at start and end of table
High Level Languages    
    & Python, Mathematica   & Statistical Languages 
                                        & Stan          \\
Low Level Languages
    & C, C\texttt{++}, CUDA & Shells    & Zsh, Bash     \\
    \end{tabularx}
\end{center}

\noindent
\lipsum[1]

\end{document}

Request to avoid text wrapping for "any cost" means, that in cases, when text in cells is to long, it will extend table width and consequently it will not end at right text border. Is this acceptable to you?

1
  • This one also works, seems to provide the same behavior as the one suggested above by Pieter. Thank you! Dec 13, 2022 at 19:50
1

Why not two tabulars?

\documentclass{article}
\usepackage[margin=1in,letterpaper]{geometry}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\noindent
\begin{tabular}[t]{@{}ll@{}}
  \textbf{High Level Languages}   & Python, Mathematica \\
  \textbf{Low Level Languages}    & C, C\texttt{++}, CUDA
\end{tabular}\hfill
\begin{tabular}[t]{@{}ll@{}}
  \textbf{Statistical Languages}  & Stan \\
  \textbf{Shells}                 & Zsh, Bash
\end{tabular}

\noindent
\lipsum[1][1-3]

\end{document}

enter image description here

If you replace with

\begin{tabular}[t]{@{}r@{\enspace}l@{}}

in both tabulars, you get

enter image description here

Not something I'd like to have; personal taste, though.

The two tabulars might be awful to type, so here's a version that accepts a much simpler user-level syntax.

\documentclass{article}
\usepackage[margin=1in,letterpaper]{geometry}
\usepackage{tabularx}
\usepackage{lipsum}

\ExplSyntaxOn

\NewDocumentCommand{\skills}{m}
 {
  \ferreira_cv_skills:n { #1 }
 }

\seq_new:N \l__ferreira_cv_skills_seq
\tl_new:N \l__ferreira_cv_skills_body_tl

\cs_new_protected:Nn \ferreira_cv_skills:n
 {
  \group_begin:
  \par\addvspace{\medskipamount}
  \seq_clear:N \l__ferreira_cv_skills_seq
  % store the skills
  \cs_set_eq:NN \skill \__ferreira_cv_skills_add:nn
  #1
  % process the skills
  \cs_set_eq:NN \skill \__ferreira_cv_skill_print:nn
  \noindent
  % first the odd skills
  \tl_clear:N \l__ferreira_cv_skills_body_tl
  \seq_indexed_map_function:NN \l__ferreira_cv_skills_seq \__ferreira_cv_skill_make_odd:nn
  \begin{tabular}[t]{@{}r@{\enspace}l@{}}
  \tl_use:N \l__ferreira_cv_skills_body_tl
  \end{tabular}
  \hfill % fill the line
  % now the even skills
  \tl_clear:N \l__ferreira_cv_skills_body_tl
  \seq_indexed_map_function:NN \l__ferreira_cv_skills_seq \__ferreira_cv_skill_make_even:nn
  \begin{tabular}[t]{@{}r@{\enspace}l@{}}
  \tl_use:N \l__ferreira_cv_skills_body_tl
  \end{tabular}
  \group_end:
  \par\addvspace{\medskipamount}
 }
\cs_new_protected:Nn \__ferreira_cv_skills_add:nn
 {
  \seq_put_right:Nn \l__ferreira_cv_skills_seq { \skill{#1}{#2} }
 }
\cs_new_protected:Nn \__ferreira_cv_skill_print:nn
 {
  \textbf{#1} & #2 \\
 }

\cs_new_protected:Nn \__ferreira_cv_skill_make_odd:nn
 {
  \int_if_odd:nT { #1 } { \tl_put_right:Nn \l__ferreira_cv_skills_body_tl { #2 } }
 }
\cs_new_protected:Nn \__ferreira_cv_skill_make_even:nn
 {
  \int_if_odd:nF { #1 } { \tl_put_right:Nn \l__ferreira_cv_skills_body_tl { #2 } }
 }

\ExplSyntaxOff

\begin{document}

\noindent
\lipsum[1][1-5]

\skills{
  \skill{High Level Languages}{Python, Mathematica}
  \skill{Statistical Languages}{Stan}
  \skill{Low Level Languages}{C, C\texttt{++}, CUDA}
  \skill{Shells}{Zsh, Bash}
}

\noindent
\lipsum[1][1-5]

\skills{
  \skill{High Level Languages}{Python, Mathematica}
  \skill{Statistical Languages}{Stan}
  \skill{Low Level Languages}{C, C\texttt{++}, CUDA}
  \skill{Shells}{Zsh, Bash}
  \skill{Typography}{\LaTeX}
}

\noindent
\lipsum[1][1-5]

\end{document}

The idea is to build the two tables taking the odd-numbered and the even-numbered items.

enter image description here

2
  • Uhm, your solution does seem to be very simple indeed. I was afraid of doing something like because I thought the lining wouldn't work, but this is probably the simplest solution, and hence, the one I can actually understand. Thanks! (I already marked the one of the previous answer as solution, but this one works just fine as well!). The only disadvantage compared to the ones before is it's lack of support for changing the width, but I imagine that that can be added easily by taking inspiration from the previous solutions. Dec 13, 2022 at 19:54
  • @JoséFerreira If you don't have unusually high text, the alignment will be right.
    – egreg
    Dec 13, 2022 at 20:38

You must log in to answer this question.

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