设置
我使用 以不同的方式分隔了 3 个段落tabular
。以下是 :
\documentclass[11pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{titlesec}
\usepackage{lipsum}
%heading
\setlength\parskip{0pt}
\titleformat{\section}
{\scshape\Large\bfseries}{}{0em}{\vspace{2pt}}[\hrule height 1pt]
\titlespacing*{\section}
{0pt}{0pt}{10pt}
%leftbar
\usepackage{array, xcolor, lipsum, bibentry}
\definecolor{lightgray}{gray}{0.8}
\newcolumntype{L}{>{\raggedleft}p{0.10\textwidth}}
\newcolumntype{R}{p{0.86\textwidth}}
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}
$----------------------------------------------------------------------------
\begin{document}
%Example 1
\section{Example of text width that is should be}
\lipsum[1]
%Example 2
\bigskip
\section{Example tabular with vRule}
\hspace{-27pt}
\begin{tabular}{L!{\VRule}R}
\textbf{name} - (date)\\&
\lipsum[1] \\
\end{tabular}
%Example 3
\bigskip
\section{Example tabular with textwidth}
\hspace{-11pt}
\begin{tabular}{r|p{0.80\textwidth}}
\emph{name}&{\bf location}\\\textsc{date}\\&
\lipsum[1]
\begin{itemize}
\item item 3
\item item 2
\item item 1
\end{itemize}\\
\end{tabular}
\end{document}
问题(第二段和第三段)
如您所见,第一个问题是文本没有与页面宽度对齐,我过去常常用\hspace{}
眼睛对齐左侧,但我无法对齐右侧。
第二个问题是文本下方有空白,并且垂直线超出了段落。
目标
我的格式哪里错了?如何让所有内容都像第一段一样放置在“统一”的图像中。
编辑:上面的代码有要包含的项目符号,但图像没有显示这一点
答案1
这是由于在计算第二列的宽度时采用了近似值,并且您没有考虑到单元格之间的一些填充(tabcolsep), in particular after the last column. You can have an exact calculation using
tabularx . Also, instead of adding a negative horizontal space before the table, approximately measured, just add
\noindent . Last, the vertical line overflow is simply a side effect of using the
\lipsum` 宏:插入真实文本时不会产生这种副作用。
以下是没有这些缺点的代码:
\documentclass[11pt]{article}
\usepackage[margin=0.5in, showframe]{geometry}
\usepackage{titlesec}
\usepackage{enumitem}
\usepackage{lipsum}
%heading
\setlength\parskip{0pt}
\titleformat{\section}
{\scshape\Large\bfseries}{}{0em}{\vspace{2pt}}[\hrule height 1pt]
\titlespacing*{\section}
{0pt}{0pt}{10pt}
%leftbar
\usepackage{tabularx, xcolor, lipsum, bigstrut}
\definecolor{lightgray}{gray}{0.8}
\newcolumntype{L}{>{\raggedleft}p{0.10\textwidth}}
\newcolumntype{R}{p{0.86\textwidth}}
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}
\begin{document}
%Example 1
\section{Example of text width that is should be}
\lipsum[1]
%Example 2
\bigskip
\section{Example tabular with vRule}
\noindent
\begin{tabularx}{\linewidth}{@{}L!{\VRule}X@{}}
\textbf{name} - (date)\\
& \lipsum[1]
\end{tabularx}
%Example 3
\bigskip
\section{Example tabular with textwidth}
\noindent
\begin{tabularx}{\linewidth}{@{}r|X@{}}
\emph{name}&{\bfseries location}\\\textsc{date}\\
&Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla
et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer
sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla.
Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget
orci sit amet orci dignissim rutrum.
\begin{itemize}[wide=0pt, leftmargin=*, after=\vspace{-\baselineskip}]
\item item 3
\item item 2
\item item 1
\end{itemize}
\end{tabularx}
\end{document}