左侧文本左对齐;中间和右侧文本右对齐

左侧文本左对齐;中间和右侧文本右对齐
{\bf Carnegie Mellon University} \hfill {LTI, School of Computer Science} \hfill {\em July 2008 - Present}
{\bf Tsinghua University} \hfill {School of Software} \hfill {\em July 2008 - Present}

上面的代码给出了这样的结果: 在此处输入图片描述

如何使中间文本右对齐?

- - - 编辑 - - -

如果这两行之间有一些内容,并且我仍然希望这两行的中间文本右对齐,该怎么办?例如:

在此处输入图片描述

答案1

除了这里的答案之外,我认为实现您想要的最灵活的方法是使用\minipage环境并应用于\flushright文本。

    \documentclass{article}

\usepackage[a4paper,margin=2cm]{geometry}

%\usepackage{minipage}

\begin{document}

\noindent \begin{minipage}{0.32\textwidth}
\textbf{Carnegie Mellon University}

\textbf{Tsinghua University}
\end{minipage}%
\begin{minipage}{0.35\textwidth}
\begin{flushright}
LTI, School of Computer Science

School of Software
\end{flushright}
\end{minipage}\hfill
\begin{minipage}{0.30\textwidth}
\begin{flushright}
July 2008 -- Present

July 2008 -- Present
\end{flushright}
\end{minipage}

\end{document}

其结果为: 对齐文本

答案2

您可以使用tabular*array以“集中”的方式设置格式:

\documentclass{article}

\usepackage[a4paper,margin=2cm]{geometry}

\usepackage{array}

\begin{document}

\noindent
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  >{\bfseries}l
  r
  >{\itshape}r
  @{}
}
Carnegie Mellon University & LTI, School of Computer Science & July 2008 -- Present \\
Tsinghua University        & School of Software              & July 2008 -- Present
\end{tabular*}

\end{document}

在此处输入图片描述

我使用它是geometry因为标准article文本宽度对于这个表来说太小了。

答案3

一个好的选择是使用表格:

在您的文档中尝试此操作

\begin{tabular}{l r r}
\textbf{ Carnegie Mellon University} & {LTI, School of Computer Science} &\textit{ July 2008 - Present}\\
\textbf{ Tsinghua University} &{School of Software} & \textit{ July 2008 - Present}\\
\end{tabular}

这是使用 tabularx 的更新

\documentclass[a4paper,10pt]{article}
\usepackage[a4paper, total={7in, 8in}]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}


\newcolumntype{L}{>{\raggedright\arraybackslash}X}%
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}%

\begin{document}

\noindent
{\bf Carnegie Mellon University} \hfill {LTI, School of Computer Science} \hfill {\em July 2008 - Present}\\
{\bf Tsinghua University} \hfill {School of Software} \hfill {\em July 2008 - Present}\vspace*{20pt}

\noindent\begin{tabularx}{\linewidth}{L R R}
\textbf{ \mbox{Carnegie Mellon University}} & {\mbox{LTI, School of Computer Science}} &\textit{ July 2008 - Present}\\
\textbf{ Tsinghua University} &{School of Software} & \textit{ July 2008 - Present}\\
\end{tabularx}

\end{document}

编辑以包含第一行和最后一行之间的文本:代码:

\documentclass[a4paper,10pt]{article}
\usepackage[a4paper, total={7in, 8in}]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}


\newcolumntype{L}{>{\raggedright\arraybackslash}X}%
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}%

\begin{document}

Your old code:

\noindent
{\bf Carnegie Mellon University} \hfill {LTI, School of Computer Science} \hfill {\em July 2008 - Present}\\
{\bf Tsinghua University} \hfill {School of Software} \hfill {\em July 2008 - Present}\vspace*{20pt}

My updated code

\noindent\begin{tabularx}{\linewidth}{L R R}
\textbf{ \mbox{Carnegie Mellon University}} & {\mbox{LTI, School of Computer Science}} &\textit{ July 2008 - Present}\\
\multicolumn{3}{p{\linewidth}}{Here you can have any possible content that can break in several lines without
causes any problem to the alligned first and last lines\ldots Be carefullldots you need to use p\verb|\linewidth|
to have this kind of line between the others!}\\
\textbf{ Tsinghua University} &{School of Software} & \textit{ July 2008 - Present}\\
\end{tabularx}

\end{document}

结果:在此处输入图片描述

使用 minipage 和 itemize 进行更新:

My updated code:\vspace*{10pt}

\noindent\begin{tabularx}{\linewidth}{L R R}
\textbf{ \mbox{Carnegie Mellon University}} & {\mbox{LTI, School of Computer Science}} &\textit{ July 2008 - Present}\\
\\
\multicolumn{3}{p{\linewidth}}{
\begin{minipage}{\linewidth}
\begin{itemize}
  \item Test item one
  \item Test second longer item
  \item These items have nothing to do with the rest alligned tabular...
 \end{itemize}
\end{minipage}}\\
\\
\textbf{ Tsinghua University} &{School of Software} & \textit{ July 2008 - Present}\\
\end{tabularx}

最后结果: 在此处输入图片描述

相关内容