我有一个环境(pseudocodeblock
来自cryptocode
包裹) 如果内容太大,则会进入边距:
现在,我可以使用\scalebox
和手动调整它的minipage
大小,但我需要手动调整设置,因为我不知道的宽度pseudocodeblock
(而且我不知道如何计算它)。
是否可以测量这个块的宽度,并在其太大而无法容纳在页面中时自动缩放它?
平均能量损失
\documentclass[]{article}
\usepackage [
n,
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\begin{document}
\noindent This block should be scaled to fit on page (ideally, if it's short enough, it is not scaled up, of its too big, it's scaled down), for now it is going in the margin:
\noindent\rule{\linewidth}{1mm}
\pseudocodeblock{
\textbf{Alice} \< \< \textbf{Bob} \\[][\hline]
\\[-.5\baselineskip]
\text{Run Alice will do some stuff that are hard to write shortly.} \< \sendmessage{<->}{} \< \text{Same for Bob}\\
}
\end{document}
答案1
varwidth
好的,我发现(提供最大宽度的上限)的组合\maxsizebox
正好提供了我想要的内容:
\documentclass[]{article}
\usepackage [
n,
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\usepackage{adjustbox}
\begin{document}
\noindent\rule{\linewidth}{1mm}
\noindent Content already short enough is not changed:
\noindent\maxsizebox{\linewidth}{!}{
\begin{varwidth}{10\linewidth}% Upper bound on the width of the text
\pseudocodeblock{
\textbf{Alice} \< \< \textbf{Bob} \\[][\hline]
\\[-.5\baselineskip]
\text{Run Alice.} \< \sendmessage{<->}{} \< \text{Run Bob}\\
}
\end{varwidth}
}
\noindent Too large content is shrinked
\noindent\maxsizebox{\linewidth}{!}{
\begin{varwidth}{10\linewidth}% Upper bound on the width of the text
\pseudocodeblock{
\textbf{Alice} \< \< \textbf{Bob} \\[][\hline]
\\[-.5\baselineskip]
\text{Run Alice will do some stuff that are hard to write shortly.} \< \sendmessage{<->}{} \< \text{Same for Bob}\\
}
\end{varwidth}
}
\end{document}
您还可以创建一个环境来自动执行此操作:
\NewDocumentEnvironment{autoFit}{O{\linewidth}}{\noindent\maxsizebox{\linewidth}{!}\bgroup%
\begin{varwidth}{10\linewidth}% Upper bound on the width of the text
}{\end{varwidth}\egroup}