我有一个两列的表格*环境,我希望自动调整每行第一个单元格的宽度以适应其内容。如何删除附图中的水平空格“x”?
MWE如下:
\documentclass{article} %
\usepackage{tabularx}
\usepackage{blindtext}
\setlength\tabcolsep{1pt}
\newenvironment{twenty}{%
\begin{tabular*}
{\textwidth}{ll}}{%
\end{tabular*}}
\newcommand{\twentyitem}[4]{%
{#1}&\parbox[t]{0.75\textwidth}{%
\textbf{#2}%
\hfill%
{#3}\\%
#4\vspace{\parsep}}\\}
\begin{document}
\begin{twenty}
\twentyitem{2017 Sept~-~%\dots
a very long date here}{ABC Position}{City, Country}%
{\blindtext}
\twentyitem{2015 May~-~%\dots
2017 Sept}{XYZ Position}{City, Country}%
{\blindtext}
\end{twenty}
\end{document}
答案1
tabularx
以下是对每个条目使用新环境的解决方案:
\documentclass{article}
\usepackage{tabularx}
\usepackage{blindtext}
\newcommand{\myentry}[4]{\begin{tabularx}{\textwidth}{lX}#1 & \textbf{#2} \hfill #3 \newline #4 \\ \end{tabularx}}
\begin{document}
\noindent
\myentry{2017 Sept - a very long date here}{ABC position}{City, Country}{\blindtext}
\myentry{2015 May~-~2017 Sept}{XYZ Position}{City, Country}{\blindtext}
\end{document}
答案2
我将使用它right alignment
作为第一列。
\documentclass{article} %
\usepackage{tabularx}
\usepackage{blindtext}
\setlength\tabcolsep{1pt}
\newenvironment{twenty}{%
\begin{tabular*}
{\textwidth}{rl}}{%
\end{tabular*}}
\newcommand{\twentyitem}[4]{%
{#1}&\parbox[t]{0.75\textwidth}{%
\textbf{#2}%
\hfill%
{#3}\\%
#4\vspace{\parsep}}\\}
\begin{document}
\begin{twenty}
\twentyitem{2017 Sept~-~%\dots
a very long date here}{ABC Position}{City, Country}%
{\blindtext}
\twentyitem{2015 May~-~%\dots
2017 Sept}{XYZ Position}{City, Country}%
{\blindtext}
\end{twenty}
\end{document}