问题描述
我想在表格中使用 minipage,但内容的对齐方式不一样。我想让第一个输入右上角和第二个输入左对齐。我使用的代码是:
\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}
}
\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.}
我应该怎么做才能让 YEAR 与下一列的文本在同一行?
解决方法
您的 minipage 不能比列宽,否则将在此之前插入换行符。在您的代码中,小页面是整个文本的宽度加 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}