![算法环境:过程参数太长](https://linux22.com/image/480279/%E7%AE%97%E6%B3%95%E7%8E%AF%E5%A2%83%EF%BC%9A%E8%BF%87%E7%A8%8B%E5%8F%82%E6%95%B0%E5%A4%AA%E9%95%BF.png)
我正在使用算法环境,函数/过程的参数太长,溢出了。我想知道解决方案是什么?我能以某种方式强制它保持在一行中还是让它很好地变成多行?我不确定。
\documentclass[12pt]{report}
\usepackage[letterpaper, portrait, margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{float}
\usepackage{framed}
\usepackage{blindtext}
\pagenumbering{gobble}
\begin{document}
\begin{algorithm}[htbp]
\caption{Simple greedy visit sequence evaluator for circular remote attribute grammar}\label{alg:crag-visit-sequence-generator}
\begin{algorithmic}
\Procedure{\texttt{VISIT\_SEQUENCE\_EVAL}}{$AG, \hat{\mathscr{D}},\mathscr{V}, \mathit{Val} = \texttt{dict()}, \mathit{history} = \texttt{dict()}, \mathit{inCycle} = \texttt{false}$}
\State \Return TODO
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
\newline
一种快速而肮脏的解决方案是在参数中使用,然后使用 重复要水平跳过的文本\phantom
,这会分配空间但实际上不会打印任何内容。因此可以添加以下内容:
\newline\phantom{\textbf{procedure} \texttt{VISIT\_SEQUENCE\_EVAL}(}
这意味着:换行,然后是打印所需的任何空间
程序访问序列评估(
然后是其余的论点。
MWE(请注意,我从参数中删除了大部分数学模式,因为不需要):
\documentclass[12pt]{report}
\usepackage[letterpaper, portrait, margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{float}
\usepackage{framed}
\usepackage{blindtext}
\pagenumbering{gobble}
\begin{document}
\begin{algorithm}[htbp]
\caption{Simple greedy visit sequence evaluator for circular remote attribute grammar}\label{alg:crag-visit-sequence-generator}
\begin{algorithmic}
\Procedure{\texttt{VISIT\_SEQUENCE\_EVAL}}{$AG, \hat{\mathscr{D}},\mathscr{V}$, \textit{Val} = \texttt{dict()}, \textit{history} = \texttt{dict()},\newline\phantom{\textbf{procedure} \texttt{VISIT\_SEQUENCE\_EVAL}(}\textit{inCycle} = \texttt{false}}
\State \Return TODO
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
结果: