如何删除“itemize”后的缩进?我希望“算法 1...”与标题和第一句从同一位置写出。
有没有比 \qquad 更好的方法来格式化文本中“输入:”和“输出:”之后的行并缩进?
\documentclass{article}
\documentclass[runningheads,a4paper]{article}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{calc}
\usepackage[a4paper,bindingoffset=0.2in,%
left=0.5in,right=0.5in,top=0.5in,bottom=0.5in,%
footskip=.25in]{geometry}
\usepackage{tabularx}
\newenvironment{algotabularx}
{\tabularx{\linewidth-\inoutsize-\widthof{~~~}-4\tabcolsep-
\rightskip}[t]}
{\endtabularx}
\begin{document}
\section{The Dijkstra’s algorithm}
The Dijkstra’s algorithm is used for finding shortest paths in a graph G = $\langle{V,E}\rangle$. The characteristics of the Dijkstra’s algorithm variant presented here are as follows:
\begin{itemize}
\item Works on a \underline{weighted graph}.
\item Only \underline{non-negative weights} are allowed.
\item Calculates minimum distances from one node $v_0$ to all the others
\item It has the complexity of $O(\left|V\right|^2)$.
\end{itemize}
Algorithm 1 presents a pseudocode for the Dijkstra’s algorithm.\\
\begin{algotabularx}{@{}p{3cm}p{0.5cm}p{10cm}X@{}}
Inputs: \\
\qquad $G = \langle{V,E}\rangle$ & - & a weighted graph \\
\qquad $v_0$ & - & the initial node to determine distances from \\
Outputs: \\
\qquad $\forall v \in V : d(v)$ & - & a set of distances from $v0$ calculated for all nodes $v \in V$ \\
\qquad $\forall v \in V : d(p)$ & - & a set of predecessors on the shortest path from v0 \\
\end{algotabularx}
\end{document}
答案1
后面的双换行符\end{itemize}
表示您正在开始一个新段落,这会导致缩进。删除其中一个换行符以表明它是同一段落的一部分:
\documentclass[runningheads,a4paper]{article}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{calc}
\usepackage[a4paper,bindingoffset=0.2in,%
left=0.5in,right=0.5in,top=0.5in,bottom=0.5in,%
footskip=.25in]{geometry}
\usepackage{tabularx}
\newenvironment{algotabularx}
{\tabularx{\linewidth-\inoutsize-\widthof{~~~}-4\tabcolsep-
\rightskip}[t]}
{\endtabularx}
\begin{document}
\section{The Dijkstra’s algorithm}
The Dijkstra’s algorithm is used for finding shortest paths in a graph G = $\langle{V,E}\rangle$. The characteristics of the Dijkstra’s algorithm variant presented here are as follows:
\begin{itemize}
\item Works on a \underline{weighted graph}.
\item Only \underline{non-negative weights} are allowed.
\item Calculates minimum distances from one node $v_0$ to all the others
\item It has the complexity of $O(\left|V\right|^2)$.
\end{itemize}
Algorithm 1 presents a pseudocode for the Dijkstra’s algorithm.\\
\begin{algotabularx}{@{}p{3cm}p{0.5cm}p{10cm}X@{}}
Inputs: \\
\qquad $G = \langle{V,E}\rangle$ & - & a weighted graph \\
\qquad $v_0$ & - & the initial node to determine distances from \\
Outputs: \\
\qquad $\forall v \in V : d(v)$ & - & a set of distances from $v0$ calculated for all nodes $v \in V$ \\
\qquad $\forall v \in V : d(p)$ & - & a set of predecessors on the shortest path from v0 \\
\end{algotabularx}
\end{document}