[英]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.