[英]Using minipage in tabular LATEX
我想在表格中使用minipage,但是alignment的内容不一样。 我想让第一个输入右上角和第二个输入左对齐。 我使用的代码是:
\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}
}
使用此代码的 output 是:
\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 不能比列宽,否则会在此之前插入换行符。 在您的代码中,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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.