4

I am trying to create my CV, using tables. I want them in the center of the page, but they continue to position a little bit to the left. I am using the command \centering before the environment tabular. I think I understood the reason, that is the text on the first column is not long enough, in the second table. How can I solve this?

enter image description here

The first table is centered, but the second, as you can noticed, is not.

This is the code:

\documentclass[12pt, Arial]{article}

\usepackage{float} % force LaTex to not reposition the tables
\usepackage{xcolor} % used to change the colour of the author
\usepackage{hyperref} % to use links 

% BEGINNING OF THE DOCUMENT
\begin{document}
%
\renewcommand{\baselinestretch}{1.3}
%
\maketitle
%
\subsection*{Personal Information}
\begin{table}[H]
    \centering
    \setlength{\tabcolsep}{25pt}
        \begin{tabular}{ r | l}
            \textbf{Name and surname} & Barack \\
            \textbf{Address} & Washington\\     
            &USA\\
            \textbf{Number} & +1231231231231 \\
            \textbf{E-mail addresses} & [email protected] \\
            \textbf{Nationality} & American \\
            \textbf{Birth} & 28/10/1923 \\
            \textbf{Gender} & Male \\
        \end{tabular}
\end{table}
%
%
\subsection*{Education}
\begin{table}[H]
    \centering
    \setlength{\tabcolsep}{25pt}
        \begin{tabular}{ r | l}
            \textbf{University} & \textcolor{blue}{\href{https://www.google.com}{google}} \\
            \textbf{Faculty} & Science of Informatics\\
            \textbf{Date} & 1900 - present \\   
            \textbf{Country} & Earth \\
        \end{tabular}
\end{table}
\end{document}
4
  • The table probably is centred. Do you want the vertical lines in the middle to align? If so, specify the column widths with something like p@{.5\linewidth} rather than r and l.
    – cfr
    Commented Oct 12, 2014 at 18:08
  • It's not a "problem" it's just a natural feature of centering that if you add text, the table moves. The second table is centred. It may be that you don't want that layout, but that's a different thing. Commented Oct 12, 2014 at 18:25
  • You do not need or want \begin{table}[H] here, just don't use \begin{table} at all, you don't want a float, just a cemtred tabular. Commented Oct 12, 2014 at 18:27
  • 1
    What does "stupid manager" in the title mean? Commented Oct 13, 2014 at 4:53

4 Answers 4

7

You want cells as wide as half the text width, but to also subtract the intercolumn padding and the rule width.

It's also better to define an environment, rather than repeating over and over the same input.

\documentclass[12pt]{article}
\usepackage{array,calc,xcolor}
\usepackage{hyperref}
\hypersetup{
  colorlinks,
  urlcolor=blue,
}

\newenvironment{data}
 {\par\centering
  \setlength{\tabcolsep}{25pt}%
  \begin{tabular}{
    @{}% no padding at the left
    >{\raggedleft\bfseries}p{.5\textwidth-\tabcolsep-.5\arrayrulewidth}% right aligned column
    |% separator
    >{\raggedright\arraybackslash}p{.5\textwidth-\tabcolsep-.5\arrayrulewidth}% left aligned column
    @{}% no padding at the right
  }}
  {\end{tabular}\par}

\linespread{1.3}

\begin{document}
  %
  %
  % \maketitle
  %
\subsection*{Personal Information}

\begin{data}
Name and surname & Barack \\
Address          & Washington\newline USA \\
Number           & +1231231231231 \\
E-mail addresses & \texttt{[email protected]} \\
Nationality      & American \\
Birth            & 28/10/1923 \\
Gender           & Male \\
\end{data}

\subsection*{Education}

\begin{data}
University & \href{https://www.google.com}{google} \\
Faculty    & Science of Informatics\\
Date       & 1900 -- present \\
Country    & Earth \\
\end{data}
\end{document}

enter image description here

3

Do you want something like this?

aligned vertical rules

\documentclass[12pt, Arial]{article}
\usepackage{array}
\usepackage{float} % force LaTex to not reposition the tables
\usepackage{xcolor} % used to change the colour of the author
\usepackage{hyperref} % to use links

% BEGINNING OF THE DOCUMENT
\begin{document}
  %
  \renewcommand{\baselinestretch}{1.3}
  %
  % \maketitle
  %
  \subsection*{Personal Information}

  {\centering
    \setlength{\tabcolsep}{25pt}
    \begin{tabular}{ >{\raggedleft}p{.5\linewidth} | p{.5\linewidth} }
      \textbf{Name and surname} & Barack \\
      \textbf{Address} & Washington\\
      &USA\\
      \textbf{Number} & +1231231231231 \\
      \textbf{E-mail addresses} & [email protected] \\
      \textbf{Nationality} & American \\
      \textbf{Birth} & 28/10/1923 \\
      \textbf{Gender} & Male \\
    \end{tabular}}
  %
  %
  \subsection*{Education}

  {\centering
    \setlength{\tabcolsep}{25pt}
    \begin{tabular}{ >{\raggedleft}p{.5\linewidth} | p{.5\linewidth} }
      \textbf{University} & \textcolor{blue}{\href{https://www.google.com}{google}} \\
      \textbf{Faculty} & Science of Informatics\\
      \textbf{Date} & 1900 - present \\
      \textbf{Country} & Earth \\
    \end{tabular}}
\end{document}
0
2

A solution with the tabularx package. It doesn't have to be centred since its total width is equal to \linewidth, and doesn't require the table environment since you do not want it to float. I managed to use Arial with the winfonts package (to install oneself: it is not part of TeX Live nor MiKTeX. Actually, it would be simpler to use it directly with Xe/LuaLaTeX and the fontspec package.

It is not recommended to change \baselinestretch as it has unwanted side effects. I replaced it with the setspace package, wich cater for those side effects, and the onehalfspacing switch.

    \documentclass[12pt, Arial]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage[x11names]{xcolor} % used to change the colour of the author
    \usepackage{tabularx, colortbl}
    \usepackage{setspace}
    \usepackage{winfonts}
    \renewcommand\sfdefault{arial}

    \usepackage{hyperref} % to use links
    % BEGINNING OF THE DOCUMENT
    \begin{document}
    \sffamily
    \onehalfspacing
    %\maketitle
    %
    \subsection*{Personal Information}
    \medskip
    \setlength{\tabcolsep}{25pt}
    \arrayrulecolor{Turquoise1!50!}\setlength\arrayrulewidth{.8pt}
    \begin{tabularx}{\linewidth}{>{\raggedleft}X | X}
    \textbf{Name and surname} & Barack \\
    \textbf{Address} & Washington\\
    &USA\\
    \textbf{Number} & +1231231231231 \\
    \textbf{E-mail addresses} & [email protected] \\
    \textbf{Nationality} & American \\
    \textbf{Birth} & 28/10/1923 \\
    \textbf{Gender} & Male \\
    \end{tabularx}

    \subsection*{Education}
    \medskip
    \begin{tabularx}{\linewidth}{>{\raggedleft}X |X}
    \textbf{University} & \textcolor{blue}{\href{https://www.google.com}{google}} \\
    \textbf{Faculty} & Science of Informatics\\
    \textbf{Date} & 1900 - present \\
    \textbf{Country} & Earth \\
    \end{tabularx}

    \end{document} 

enter image description here

1

One solution using the package tabu.

\documentclass[12pt, Arial]{article}

\usepackage{float} % force LaTex to not reposition the tables
\usepackage{xcolor} % used to change the colour of the author
\usepackage{hyperref} % to use links 
\usepackage{tabu}

% BEGINNING OF THE DOCUMENT
\begin{document}
%
\renewcommand{\baselinestretch}{1.3}

\subsection*{Personal Information}
\begin{table}[H]
    \centering
    \setlength{\tabcolsep}{25pt}
        \begin{tabu}{>{\bfseries} X[r] | X[l]}
            Name and surname & Barack \\
            Address & Washington\\     
            &USA\\
            Number & +1231231231231 \\
            E-mail addresses & [email protected] \\
            Nationality & American \\
            Birth & 28/10/1923 \\
            Gender & Male \\
        \end{tabu}
\end{table}
%
%
\subsection*{Education}
\begin{table}[H]
    \centering
    \setlength{\tabcolsep}{25pt}
        \begin{tabu}{>{\bfseries} X[r]|X[l]}
            University & \textcolor{blue}{\href{https://www.google.com}{google}} \\
            Faculty & Science of Informatics\\
            Date & 1900 - present \\   
            Country & Earth \\
        \end{tabu}
\end{table}
\end{document}
0

You must log in to answer this question.