LaTeX 算法环境宽度调整
LaTeX中algorithm
环境是默认占据整个栏的宽度,如果想改变算法的宽度该怎么办呢?
解决方案
主要通过minipage
代码
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{float}
\title{\textbf{\LaTeX~Algorithm Width}}
\author{Xovee Xu\\https://xovee.cn}
\date{September 2022}
\begin{document}
\maketitle
\begin{algorithm}[H]
\caption{This algorithm occupies the full width}
\label{alg:xovee}
\begin{algorithmic}[1]
\State Xovee is handsame.
\State Xovee is cool.
\State Does he?
\end{algorithmic}
\end{algorithm}
\begin{center} % center algorithm
\begin{minipage}{.7\linewidth} % mini-page
\begin{algorithm}[H]
\caption{70\% of the column width!}
\label{alg:xovee}
\begin{algorithmic}[1]
\State Xovee is handsame.
\State Xovee is cool.
\State Does he?
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{center}
\end{document}
效果:
注意:环境位置使用H
使用默认的浮动环境位置,例如h
、t
、b
等
在minipage
环境外套一个figure
环境:
\begin{figure}[htb] % position argument you want
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H] % still H not h
......
Reference
- Werner. Adjust width of algorithm float. Accessed at Sept 12, 2022. Retrieved from https://tex.stackexchange.com/questions/350434/adjust-width-of-algorithm-float