我怎样才能将这个 tikzpicture 调整到适合我的 a4 页面?

我怎样才能将这个 tikzpicture 调整到适合我的 a4 页面?

我如何调整此 tikzpicture 以适应我的 a4 页面?我将其写在段落之后。但它位于标题之前,位于页面顶部。

 \documentclass{ltxdoc}
    \usepackage[demo]{tikzpeople}
    \usepackage[OT1]{fontenc}
    \usepackage{hyperref}
    \usepackage{microtype}
    \usepackage{xspace}
    \usepackage[most]{tcolorbox}
    \usepackage[title]{appendix}
    \usetikzlibrary{shapes.callouts}
    \begin{document}
\section{Commintment} 
//explanation some
\begin{figure}
        \begin{tikzpicture}[font=\small]
                    \node[alice,minimum size=1.5cm] (A) {};
                    \node[bob,right=3cm of A,minimum size=1.5cm,mirrored] (B) {};
                    \node[anchor=north east] at (A.north west) (a2) {$(\mathsf{com},\mathsf{dec}) \gets \mathsf{Com}(a)$};
                    \node[anchor=south] at (a2.north) (a1) {$a\gets\{0,1\}$};
                    \node[anchor=south west] at (B.south east){$a \gets \mathsf{Opn}(\mathsf{com},\mathsf{dec})$};
                    \draw (A.35) edge[->] node[above] {$\mathsf{com}$} (B.145);
                    \node[anchor=south west] at (B.east |- B.180) {$b\gets\{0,1\}$};
                    \draw (A.0) edge[<-] node[above] {$b$} (B.180);
                    \draw (A.325) edge[->] node[above] {$\mathsf{dec}$} (B.215);
                    \draw (A.270) ++(0,-.5) node {$a\oplus b$} edge[<-] (A.270);
                    \draw (B.270) ++(0,-.5) node {$a\oplus b$} edge[<-] (B.270);
                \end{tikzpicture}
                \caption{A secure coin flipping protocol constructed from bit commitment.}
                \label{fig:protocolexample}
            \end{figure}

    \end{document}

答案1

对图形使用一些位置说明符。例如,请参阅此处的详细答案:如何影响 LaTeX 中图形和表格等浮动环境的位置? 或者这里:[t] 和 [ht] 是什么意思?

如果您只是删除figure环境,您将无法添加标题和标签。在您的 MWE 中,我添加了位置[ht],它将尝试将图形放在插入点或下一页的顶部。

\documentclass{ltxdoc}
    \usepackage[demo]{tikzpeople}
    \usepackage[OT1]{fontenc}
    \usepackage{hyperref}
    \usepackage{microtype}
    \usepackage{xspace}
    \usepackage[most]{tcolorbox}
    \usepackage[title]{appendix}
    \usetikzlibrary{shapes.callouts}
    \usepackage{lipsum}
    \begin{document}
\section{Commintment} 
\lipsum[2]
\begin{figure}[ht]
        \begin{tikzpicture}[font=\small]
                    \node[alice,minimum size=1.5cm] (A) {};
                    \node[bob,right=3cm of A,minimum size=1.5cm,mirrored] (B) {};
                    \node[anchor=north east] at (A.north west) (a2) {$(\mathsf{com},\mathsf{dec}) \gets \mathsf{Com}(a)$};
                    \node[anchor=south] at (a2.north) (a1) {$a\gets\{0,1\}$};
                    \node[anchor=south west] at (B.south east){$a \gets \mathsf{Opn}(\mathsf{com},\mathsf{dec})$};
                    \draw (A.35) edge[->] node[above] {$\mathsf{com}$} (B.145);
                    \node[anchor=south west] at (B.east |- B.180) {$b\gets\{0,1\}$};
                    \draw (A.0) edge[<-] node[above] {$b$} (B.180);
                    \draw (A.325) edge[->] node[above] {$\mathsf{dec}$} (B.215);
                    \draw (A.270) ++(0,-.5) node {$a\oplus b$} edge[<-] (A.270);
                    \draw (B.270) ++(0,-.5) node {$a\oplus b$} edge[<-] (B.270);
                \end{tikzpicture}
                \caption{A secure coin flipping protocol constructed from bit commitment.}
                \label{fig:protocolexample}
            \end{figure}

\lipsum[2]
    \end{document}

相关内容