这只是几厘米的问题:)
该部分的代码如下:
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [thick,-]
\begin{tikzpicture}[node distance=2cm]
\centering
\node (mario) [startstop] {Mario};
\node (sara) [startstop, xshift=10cm] {Sara};
\node (convert_m) [process, below of=sara] {Converte $m=78392$};
\node (gen_p_g_a) [process, below of=mario] {Genera $p=104743$, $g=6$ e $a=31152$};
\node (gen_k) [process, below of=convert_m] {Genera $k=4189$};
\node (calcA) [process, below of=gen_p_g_a] {Calcola $A\equiv_p38041$};
\node (invia_A_g) [process, below of=calcA, xshift=5cm] {Invia $A$ e $g$};
\node (riceve_A_g) [process, below of=gen_k] {Riceve $A$ e $g$};
\node (calc_c1_c2) [process, below of=riceve_A_g, text width=3cm] {Calcola $c_1\equiv_p 20758$ \\ e $c_2\equiv_p 18244$};
\node (invia_c1_c2) [process, below of= invia_A_g] {Invia $(c_1,c_2)$};
\node (calc_x) [process, below of=calcA, yshift=-2cm] {Calcola $x^{-1}\equiv_p 56798$};
\node (ottiene_m) [process, below of=calc_x] {Ottiene $m\equiv_p x^{-1}c_2\equiv_p 78392$};
\draw [arrow] (sara) -- (convert_m);
\draw [arrow] (convert_m) -- (gen_k);
\draw [arrow] (gen_k) -- (riceve_A_g);
\draw [arrow] (mario) -- (gen_p_g_a);
\draw [arrow] (gen_p_g_a) -- (calcA);
\draw [arrow] (calcA) -- +(0,-2) -- (invia_A_g);
\draw [arrow] (invia_A_g) -- (riceve_A_g);
\draw [arrow] (riceve_A_g) -- (calc_c1_c2);
\draw [arrow] (calc_c1_c2) -- (invia_c1_c2);
\draw [arrow] (invia_c1_c2) -- (calc_x);
\draw [arrow] (calc_x) -- (ottiene_m);
\end{tikzpicture}
答案1
我会重画你的图画……
- 重新定义图片元素样式(所有“过程”节点具有相同的宽度)
tikzpicture
节点和箭头样式作为选项插入- 用于节点定位的
positioning
库语法使用 - 确定并使用节点之间共同的水平和垂直距离
- 图片绘制将从“Sara”节点开始
\documentclass[12pt]{article}
\usepackage{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning}
\makeatletter
\tikzset{suspend join/.code={\def\tikz@after@path{}}}
\makeatother
\begin{document}
\lipsum[66]
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
node distance=6mm and 8mm,
start chain = going below,
%
base/.style = {draw, text width = 40mm, align=center},
startstop/.style = {base, rounded corners, text width = 20mm},
process/.style = {base},
arr/.style = {-Stealth, thick},
every join/.style = {arr}
]
\begin{scope}[nodes={base,on chain, join}]
\node (sara) [startstop] {Sara};
\node (convert_m) [process] {Converte $m=78392$};
\node (gen_k) [process] {Genera\\ $k=4189$};
\node (riceve_A_g) [process] {Riceve $A$ e $g$};
\node (calc_c1_c2) [process] {Calcola\\ $c_1\equiv_p 20758$ \\ e $c_2\equiv_p 18244$};
\end{scope}
\node (invia_A_g) [process,
left=of riceve_A_g] {Invia $A$ e $g$};
\node (invia_c1_c2) [process,
left = of calc_c1_c2] {Invia $(c_1,c_2)$};
\begin{scope}[nodes={base,on chain, join}]
\node (mario) [startstop,
suspend join,
left= 80mm of sara] {Mario}; % 50mm = 11mm+8mm+42mm+8mm+11mm
\node (gen_p_g_a) [process] {Genera $p=104743$, $g=6$ e $a=31152$};
\node (calcA) [process] {Calcola $A\equiv_p38041$};
\end{scope}
\node (calc_x) [process,
left=of invia_c1_c2] {Calcola $x^{-1}\equiv_p 56798$};
\node (ottiene_m) [process, below=of calc_x] {Ottiene $m\equiv_p x^{-1}c_2\equiv_p 78392$};
% arrows out of join macro
\draw[arr] (calcA) |- (invia_A_g);
\draw[arr] (invia_A_g) -- (riceve_A_g);
\draw[arr] (calc_c1_c2) -- (invia_c1_c2);
\draw[arr] (invia_c1_c2) -- (calc_x);
\draw[arr] (calc_x) -- (ottiene_m);
\end{tikzpicture}
\end{figure}
\end{document}
(红线表示页面布局)
答案2
首先,你可以提出一个最小的可编译代码,在这里我们甚至不知道你正在使用哪个类。否则,要回答,changepage 包允许使用环境 \begin{adjustwidth}{...}{...} 本地修改边距。因为在这里你必须将浮动元素置于页面中央,所以你必须将此环境置于浮动元素中。
注意:我选择不修改图像以使其更紧凑,而是为了回答一个更普遍的问题,即使图像大于文本框居中
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{changepage}
\usepackage{longtable}
\begin{document}
\lipsum[1]
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [thick,-]
%\lipsum[2]
\begin{figure}[!htb]
\begin{adjustwidth}{-1cm}{-1cm}
\centering
\begin{tikzpicture}[node distance=2cm]
\node (mario) [startstop] {Mario};
\node (sara) [startstop, xshift=10cm] {Sara};
\node (convert_m) [process, below of=sara] {Converte $m=78392$};
\node (gen_p_g_a) [process, below of=mario] {Genera $p=104743$, $g=6$ e $a=31152$};
\node (gen_k) [process, below of=convert_m] {Genera $k=4189$};
\node (calcA) [process, below of=gen_p_g_a] {Calcola $A\equiv_p38041$};
\node (invia_A_g) [process, below of=calcA, xshift=5cm] {Invia $A$ e $g$};
\node (riceve_A_g) [process, below of=gen_k] {Riceve $A$ e $g$};
\node (calc_c1_c2) [process, below of=riceve_A_g, text width=3cm] {Calcola $c_1\equiv_p 20758$ \\ e $c_2\equiv_p 18244$};
\node (invia_c1_c2) [process, below of= invia_A_g] {Invia $(c_1,c_2)$};
\node (calc_x) [process, below of=calcA, yshift=-2cm] {Calcola $x^{-1}\equiv_p 56798$};
\node (ottiene_m) [process, below of=calc_x] {Ottiene $m\equiv_p x^{-1}c_2\equiv_p 78392$};
\draw [arrow] (sara) -- (convert_m);
\draw [arrow] (convert_m) -- (gen_k);
\draw [arrow] (gen_k) -- (riceve_A_g);
\draw [arrow] (mario) -- (gen_p_g_a);
\draw [arrow] (gen_p_g_a) -- (calcA);
\draw [arrow] (calcA) -- +(0,-2) -- (invia_A_g);
\draw [arrow] (invia_A_g) -- (riceve_A_g);
\draw [arrow] (riceve_A_g) -- (calc_c1_c2);
\draw [arrow] (calc_c1_c2) -- (invia_c1_c2);
\draw [arrow] (invia_c1_c2) -- (calc_x);
\draw [arrow] (calc_x) -- (ottiene_m);
\end{tikzpicture}
\caption{bla bla}
\label{fig:}
\end{adjustwidth}
\end{figure}
\lipsum[2]
\end{document}