微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在表格 LATEX 中使用 minipage

如何解决在表格 LATEX 中使用 minipage

我想在表格中使用 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.}

enter image description here

我应该怎么做才能让 YEAR 与下一列的文本在同一行?

解决方法

您的 minipage 不能比列宽,否则将在此之前插入换行符。在您的代码中,小页面是整个文本的宽度加 1 厘米,但您的列只有 1 厘米。

为了避免问题:

  1. 使列更宽
  2. 对小页面使用 \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}

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。