Box 相当于 shortstack,但允许更改行距

Box 相当于 shortstack,但允许更改行距

我需要一个与 完全相同的文本框\shortstack,特别是

  • 多行
  • 具有水平对齐选项
  • 垂直对齐至顶部
  • 不需要我指定高度/宽度,而是自动调整到内容

但允许我设置行距(不幸的是\shortstack具体没有不是去做)。

是否有合适的宏可用?

PS 我在一个picture环境中。

答案1

这是一个\Shotstack本质上与通常的宏相同的宏,但有一个额外的强制参数,即堆栈内容\shortstack的值:\baselineskip

\makeatletter
\gdef\Shortstack{\@ifnextchar[\@Shortstack{\@Shortstack[c]}}
\gdef\@Shortstack[#1]#2{%
  \leavevmode
  \vbox\bgroup
    \baselineskip-\p@\lineskip 3\p@
    \let\mb@l\hss\let\mb@r\hss
    \expandafter\let\csname mb@#1\endcsname\relax
    \let\\\@stackcr\setlength{\baselineskip}{#2}%
    \@ishortstack}
\makeatother

句法:

\Shortstack[<alignment>]{<baselineskip>}{<contents>}

例子:

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\gdef\Shortstack{\@ifnextchar[\@Shortstack{\@Shortstack[c]}}
\gdef\@Shortstack[#1]#2{%
  \leavevmode
  \vbox\bgroup
    \baselineskip-\p@\lineskip 3\p@
    \let\mb@l\hss\let\mb@r\hss
    \expandafter\let\csname mb@#1\endcsname\relax
    \let\\\@stackcr\setlength{\baselineskip}{#2}%
    \@ishortstack}
\makeatother

\begin{document}
\lipsum[1]

\def\MidSeasonEpisodes{Some filler to occupy space}

\Shortstack[l]{1.5em}{\MidSeasonEpisodes\\\MidSeasonEpisodes\\\MidSeasonEpisodes\\\MidSeasonEpisodes}

\lipsum[2]
\end{document}

在此处输入图片描述

我不知道为什么,但是前后的空间\Shortstack似乎乱了...如果有人知道,请告诉我...

答案2

您可以使用stackengine包轻松完成此操作。该Shortunderstack命令将其对齐在顶部,并且有一个可选参数用于内容的水平参数。

使用的线的垂直间距设置为 \setstackgap[S]{some value} (default: 3pt)

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{ebgaramond}
\usepackage[usestackEOL]{stackengine}

\begin{document}

She puzzled over this for some time, but at last a bright thought struck
her. ‘Why, it’s a Looking-glass book, of course! And if I hold it up to
a glass, the words will all go the right way again.’

This was the poem that Alice read:
%
\Shortunderstack[l]{Beware the Jabberwock, my son!\\
The jaws that bite, the claws that catch!\\
Beware the Jubjub bird, and shun\\
The frumious Bandersnatch!\\}

‘It seems very pretty,’ she said when she had finished it, ‘but it’s
RATHER hard to understand!’ (You see she didn’t like to confess, even
to herself, that she couldn’t make it out at all.) ‘Somehow it seems
to fill my head with ideas--only I don’t exactly know what they are!
However, SOMEBODY killed SOMETHING: that’s clear, at any rate--’

\end{document} 

在此处输入图片描述

答案3

您可以使用\shortstack使用\strut以使其受到基线的影响,或者使用tabular

在此处输入图片描述

\documentclass{article}

\begin{document}



\begin{picture}(10,10)


\put(0,0){x
{\shortstack{a\\b\\C\\1}} 
{\shortstack{\strut a\\\strut b\\\strut C\\\strut 2}} 
{\linespread{1.5}\selectfont\shortstack[t]{\strut a\\\strut b\\\strut C\\\strut 3}} 
{\linespread{2}\selectfont\shortstack[t]{\strut a\\\strut b\\\strut C\\\strut 4}} 
{\begin{tabular}[b]{@{}l@{}}a\\b\\C\\5\end{tabular}} 
{\renewcommand\arraystretch{1.5}\begin{tabular}[b]{@{}l@{}}a\\b\\C\\6\end{tabular}} 
{\renewcommand\arraystretch{2}\begin{tabular}[b]{@{}l@{}}a\\b\\C\\7\end{tabular}} 
}
\end{picture}
\end{document}

相关内容