2

trying to build my CV here with Latex. I have found a template, https://github.com/btskinner/tex_cv/blob/master/cv.tex. What I do not understand is why in the example below, the two tables are not aligned, although as far as I can see the code should align them? That's how it compiles for me:

enter image description here

How do I get the 2020 & XXXX as well as the "Something, somwhere" & test to be aligned? Thanks!

\documentclass[11pt]{article}
\newcommand{\recentyear}{1900}  % artificially low year to include everything

% ------------------------------------------------------------------------------
% HEADER STUFF (CAN LEAVE ALONE UNLESS YOU WANT TO PERSONALIZE)
% ------------------------------------------------------------------------------

% -------------------------------
% Packages
% -------------------------------

\usepackage[margin=1in]{geometry} % for margins
\usepackage[american]{babel}      % for language

      % for reference sections


\usepackage{titlesec}             % to adjust section headers
\usepackage{tabularx}             % for fluid tables

% -------------------------------
% Macros


\newcommand{\RR}{\raggedright\arraybackslash} % left justified
\newcommand{\RL}{\raggedleft\arraybackslash}  % right justified

% for tables to keep consistent alignment across sections
\newcolumntype{\twocols}{>{\RR}p{1.25in}>{\RR}X}
\newcolumntype{\threecols}{>{\RR}p{1.25in}>{\RR}X>{\RL}p{1in}}

\begin{document}

\section*{Education}
\begin{center}
    \vspace{-1.5em}
    \rule{\textwidth}{0.5pt}  
\end{center}

\begin{tabularx}{\linewidth}{\threecols}
 2020 (expected) &Something, somewhere & Ph.D. \\ % or YYYY (expected)
 
\end{tabularx}


\section*{Grants and Scholarships}
\begin{center}
    \vspace{-1.5em}
    \rule{\textwidth}{0.5pt}  
\end{center}
\begin{tabularx}{\linewidth}{\threecols}
    YYYY & test & bb \\
    YYYY - YYYY & Fellowship & \$ AMOUNT \\ % if normal in your field
    
\end{tabularx}  
\end{document}
2
  • Remove the empty line between the first \end{center} and \begin{tabularx}.
    – leandriis
    Commented Nov 3, 2020 at 17:40
  • So simple...thanks!!
    – SC W
    Commented Nov 3, 2020 at 18:21

1 Answer 1

3

I'd use macros and no tabularx:

\documentclass[11pt]{article}
\usepackage{array}
% -------------------------------
% Packages
% -------------------------------

\usepackage[margin=1in]{geometry} % for margins
\usepackage[american]{babel}      % for language

      % for reference sections


\usepackage{titlesec}             % to adjust section headers
\usepackage{tabularx}             % for fluid tables

\newcommand{\recentyear}{1900}  % artificially low year to include everything

\titleformat{\section}
 {\bfseries\Large}
 {}% no number
 {0pt}% no space
 {}% the title
 [\titlerule]

% ------------------------------------------------------------------------------
% HEADER STUFF (CAN LEAVE ALONE UNLESS YOU WANT TO PERSONALIZE)
% ------------------------------------------------------------------------------


% -------------------------------
% Macros

\newcommand{\twocolsection}[2]{%
  \section{#1}
  \begin{tabular}[t]{
    @{}
    wl{1.25in}
    >{\raggedright\arraybackslash}p{\dimexpr\textwidth-1.25in-2\tabcolsep}
    @{}
  }
  #2
  \end{tabular}\par
}
\newcommand{\threecolsection}[2]{%
  \section{#1}
  \begin{tabular}[t]{
    @{}
    wl{1.25in}
    >{\raggedright\arraybackslash}p{\dimexpr\textwidth-2.25in-4\tabcolsep}
    wr{1in}
    @{}
  }
  #2
  \end{tabular}\par
}

\begin{document}

\threecolsection{Education}{
 2020 (expected) &Something, somewhere & Ph.D. \\ % or YYYY (expected)
}

\threecolsection{Grants and Scholarships}{
    YYYY & test & bb \\
    YYYY - YYYY & Fellowship & \$ AMOUNT \\ % if normal in your field
}

\end{document}

enter image description here

You might parametrize the width of the first and last column, in case the data for the specific CV doesn't fit.

This way you don't risk that the tabular is detached from the title.


A more polished version where the column widths (first and third) are parametrized, so you can change their size in the appropriate spot in the preamble. Also \twocolsection and \threecolsection have an optional argument which should be L (default) or J, for specifying left alignment (ragged right) or justification in the main column.

\documentclass[11pt]{article}

\usepackage[margin=1in]{geometry} % for margins
\usepackage[american]{babel}      % for language
\usepackage{titlesec}             % to adjust section headers
\usepackage{array}

% customization of sections

\titleformat{\section}
 {\bfseries\Large}
 {}% no number
 {0pt}% no space
 {}% the title
 [\titlerule]

% main macros

\newlength{\firstcol}
\newlength{\thirdcol}

% helper column types
\newcolumntype{L}[2]{%
  >{\raggedright\arraybackslash}p{\dimexpr\textwidth-(#1)-#2\tabcolsep\relax}%
}
\newcolumntype{J}[2]{%
  p{\dimexpr\textwidth-(#1)-#2\tabcolsep\relax}%
}

\newcommand{\twocolsection}[3][L]{%
  \section{#2}
  \begin{tabular}[t]{
    @{}
    wl{\firstcol}
    #1{\firstcol}{2}
    @{}
  }
  #3
  \end{tabular}\par
}
\newcommand{\threecolsection}[3][L]{%
  \section{#2}
  \begin{tabular}[t]{
    @{}
    wl{\firstcol}
    #1{\firstcol+\thirdcol}{4}
    wr{\thirdcol}
    @{}
  }
  #3
  \end{tabular}\par
}

%%% final customization
\setlength{\firstcol}{1.25in}
\setlength{\thirdcol}{1in}
%%%

\begin{document}

\threecolsection{Education}{
  2020 (expected) &Something, somewhere & Ph.D. \\ % or YYYY (expected)
}

\threecolsection{Grants and Scholarships}{
  YYYY & test & bb \\
  YYYY - YYYY & Fellowship & \$ AMOUNT \\ % if normal in your field
}

\twocolsection{Whatever}{
  YYYY & something long to need being split across lines; let's just
         write long enough nonsense and see
}

\twocolsection[J]{Whatever}{
  YYYY & something long to need being split across lines; let's just
         write long enough nonsense and see
}

\end{document}

enter image description here


Another version where you can separate items in each list by some vertical space. One needs higher level methods to ensure that the space is added only between items, using \addlinespace provided by booktabs.

\documentclass[11pt]{article}

\usepackage[margin=1in]{geometry} % for margins
\usepackage[american]{babel}      % for language
\usepackage{titlesec}             % to adjust section headers
\usepackage{array}
\usepackage{booktabs}

% customization of sections

\titleformat{\section}
 {\bfseries\Large}
 {}% no number
 {0pt}% no space
 {}% the title
 [\titlerule]

% main macros

\newlength{\firstcol}
\newlength{\thirdcol}

% helper column types
\newcolumntype{L}[2]{%
  >{\raggedright\arraybackslash}p{\dimexpr\textwidth-(#1)-#2\tabcolsep\relax}%
}
\newcolumntype{J}[2]{%
  p{\dimexpr\textwidth-(#1)-#2\tabcolsep\relax}%
}

\ExplSyntaxOn

\NewDocumentCommand{\twocolsection}{ O{L} m +m }
 {
  \section{#2}
  \begin{tabular}[t]{
    @{}
    wl{\firstcol}
    #1{\firstcol}{2}
    @{}
  }
  \scw_cv_table:n { #3 }
  \end{tabular}\par
 }
\NewDocumentCommand{\threecolsection}{ O{L} m +m }
 {
  \section{#2}
  \begin{tabular}[t]{
    @{}
    wl{\firstcol}
    #1{\firstcol+\thirdcol}{4}
    wr{\thirdcol}
    @{}
  }
  \scw_cv_table:n { #3 }
  \end{tabular}\par
 }

\seq_new:N \l__scw_cv_rows_seq
\tl_new:N \l__scw_cv_last_tl

\cs_new_protected:Nn \scw_cv_table:n
 {
  % get the rows
  \seq_set_split:Nnn \l__scw_cv_rows_seq { \\ } { #1 }
  % remove the last item if empty
  \seq_pop_right:NN \l__scw_cv_rows_seq \l__scw_cv_last_tl
  \tl_if_blank:VF \l__scw_cv_last_tl
   {% not blank, reinsert it
    \seq_put_right:NV \l__scw_cv_rows_seq \l__scw_cv_last_tl
   }
  % deliver the rows separated by \\ \addlinespace
  \seq_use:Nn \l__scw_cv_rows_seq { \\ \addlinespace }
 }

\ExplSyntaxOff

%%% final customization
\setlength{\firstcol}{1.25in}
\setlength{\thirdcol}{1in}
%\setlength{\defaultaddspace}{0.5em} % this is the default in booktabs
%%%

\begin{document}

\threecolsection{Education}{
  2020 (expected) &Something, somewhere & Ph.D. \\ % or YYYY (expected)
}

\threecolsection{Grants and Scholarships}{
  YYYY & test & bb \\
  YYYY - YYYY & Fellowship & \$ AMOUNT \\ % if normal in your field
}

\twocolsection{Whatever}{
  YYYY & something long to need being split across lines; let's just
         write long enough nonsense and see
}

\twocolsection[J]{Whatever}{
  YYYY & something long to need being split across lines; let's just
         write long enough nonsense and see
}

\end{document}

Experiment with different values of \defaultaddspace.

enter image description here

For dealing also with subsections, I suggest a slightly different syntax that avoids some code duplication.

\documentclass[11pt]{article}

\usepackage[margin=1in]{geometry} % for margins
\usepackage[american]{babel}      % for language
\usepackage{titlesec}             % to adjust section headers
\usepackage{array}
\usepackage{booktabs}

% customization of sections

\titleformat{\section}
 {\bfseries\Large}
 {}% no number
 {0pt}% no space
 {}% the title
 [\titlerule]
\titlespacing*{\section}{0pt}{*2}{*1}

\titleformat{\subsection}
 {\bfseries\normalsize}
 {}% no number
 {0pt}% no space
 {}% the title
 [\titlerule]
\titlespacing*{\subsection}{0pt}{*1}{*0.5}

% main macros

\newlength{\firstcol}
\newlength{\thirdcol}

% helper column types
\newcolumntype{L}[2]{%
  >{\raggedright\arraybackslash}p{\dimexpr\textwidth-(#1)-#2\tabcolsep\relax}%
}
\newcolumntype{J}[2]{%
  p{\dimexpr\textwidth-(#1)-#2\tabcolsep\relax}%
}

\ExplSyntaxOn

\NewDocumentCommand{\twocol}{ m O{L} m +m }
 {
  #1{#3}
  \begin{tabular}[t]{
    @{}
    wl{\firstcol}
    #2{\firstcol}{2}
    @{}
  }
  \scw_cv_table:n { #4 }
  \end{tabular}\par
 }
\NewDocumentCommand{\threecol}{ m O{L} m +m }
 {
  #1{#3}
  \begin{tabular}[t]{
    @{}
    wl{\firstcol}
    #2{\firstcol+\thirdcol}{4}
    wr{\thirdcol}
    @{}
  }
  \scw_cv_table:n { #4 }
  \end{tabular}\par
 }

\seq_new:N \l__scw_cv_rows_seq
\tl_new:N \l__scw_cv_last_tl

\cs_new_protected:Nn \scw_cv_table:n
 {
  % get the rows
  \seq_set_split:Nnn \l__scw_cv_rows_seq { \\ } { #1 }
  % remove the last item if empty
  \seq_pop_right:NN \l__scw_cv_rows_seq \l__scw_cv_last_tl
  \tl_if_blank:VF \l__scw_cv_last_tl
   {% not blank, reinsert it
    \seq_put_right:NV \l__scw_cv_rows_seq \l__scw_cv_last_tl
   }
  % deliver the rows separated by \\ \addlinespace
  \seq_use:Nn \l__scw_cv_rows_seq { \\ \addlinespace }
 }

\ExplSyntaxOff

%%% final customization
\setlength{\firstcol}{1.25in}
\setlength{\thirdcol}{1in}
%\setlength{\defaultaddspace}{0.5em} % this is the default in booktabs
%%%

\begin{document}

\threecol\section{Education}{
  2020 (expected) &Something, somewhere & Ph.D. \\ % or YYYY (expected)
}

\threecol\section{Grants and Scholarships}{
  YYYY & test & bb \\
  YYYY - YYYY & Fellowship & \$ AMOUNT \\ % if normal in your field
}

\twocol\subsection{Whatever}{
  YYYY & something long to need being split across lines; let's just
         write long enough nonsense and see
}

\twocol\subsection[J]{Whatever}{
  YYYY & something long to need being split across lines; let's just
         write long enough nonsense and see
}

\end{document}

enter image description here

7
  • Thanks, I was just starting to puzzle over the various lengths of the column!
    – SC W
    Commented Nov 4, 2020 at 10:17
  • @SCW I added a more polished version.
    – egreg
    Commented Nov 4, 2020 at 10:36
  • Thanks! I just got started on tables in Latex, so this is very helpful. May I ask, how can I marginally increase the space between different column lines, so it's a bit easier to read?
    – SC W
    Commented Nov 4, 2020 at 10:52
  • 1
    @SCW I added another version for spacing the items in each list.
    – egreg
    Commented Nov 4, 2020 at 13:02
  • How could one adapt the second solution for the \subsection level, too?
    – SC W
    Commented Nov 6, 2020 at 16:20

You must log in to answer this question.

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