定心台

定心台

我正在尝试使用表格创建我的简历。我希望它们位于页面的中心,但它们仍然位于稍微靠左的位置。我\centering在环境之前使用命令tabular。我想我明白了原因,那就是第二张表格中第一列的文本不够长。我该如何解决这个问题?

在此处输入图片描述

第一个表格居中,但是正如您所注意到的,第二个表格却没有居中。

这是代码:

\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}

答案1

您希望单元格的宽度为文本宽度的一半,但也要减去列间填充和规则宽度。

定义一个环境也是更好的选择,而不是一遍又一遍地重复相同的输入。

\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}

在此处输入图片描述

答案2

你想要这样的东西吗?

对齐垂直规则

\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}

答案3

使用软件包的解决方案tabularx。它不必居中,因为它的总宽度等于 \linewidth,并且不需要环境,table因为您不希望它浮动。我设法使用Arial该软件包(自行安装:它不是 TeX Live 或 MiKTeX 的一部分。实际上,将它与 Xe/LuaLaTeX 和软件包一起winfonts使用会更简单。directlyfontspec

不建议更改,\baselinestretch因为它会产生不良副作用。我setspace用可以解决这些副作用的软件包和onehalfspacingswitch 替换了它。

    \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} 

在此处输入图片描述

答案4

使用包的一个解决方案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}

相关内容