我想在表格中使用迷你页,但内容的对齐方式不一样。我想让第一个输入位于右上角,第二个输入左对齐。我使用的代码是:
\newlength{\smallertextwidth}
\setlength{\smallertextwidth}{\textwidth}
\addtolength{\smallertextwidth}{-2cm}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcommand{\mytabb}[2]{
\begin{tabular}{R{1.5cm}L{1cm}}
\textbf{#1} &
\begin{minipage}{\smallertextwidth}
#2
\end{minipage}
\end{tabular}
}
Run Code Online (Sandbox Code Playgroud)
使用此代码的输出是:
\mytabb{YEAR}{This is a long text. This is a long text.This is a long text.This is a long text.This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. \newline This is a long text. This is a long text.This is a long text.This is a long text. This is a long text.This is a long text. This is a long text.}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能将年份与下一列的文本放在同一行?
您的小页不能比列宽,否则将在其之前插入换行符。在你的代码中,迷你页是整个文本的宽度加上 1 厘米,但你的列只有 1 厘米。
为了避免这个问题:
\linewidth小型页面,因为与 textwidth 相比,这将适应列中的可用空间。\documentclass{article}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcommand{\mytabb}[2]{
\begin{tabular}{R{1.5cm}L{9cm}}
\textbf{#1} &\begin{minipage}[t]{\linewidth}
#2
\end{minipage}
\end{tabular}
}
\begin{document}
\mytabb{YEAR}{This is a long text. This is a long text.This is a long text.This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. \newline This is a long text. This is a long text.This is a long text.This is a long text. This is a long text.This is a long text. This is a long text.}
\end{document}
Run Code Online (Sandbox Code Playgroud)