将 tikzpicture 流程图居中

将 tikzpicture 流程图居中

我正在尝试建立 PRISMA 流程图。

我在一篇旧帖子中发现了@Zarko 和@Sergej 的优秀代码:

\begin{tikzpicture}[
    node distance=15mm and 10mm,
    start chain=going below,
    mynode/.style = {
        draw, rectangle, align=center, text width=5cm,
        font=\small, inner sep=3ex, outer sep=0pt,
        on chain},
    mylabel/.style = {
        draw, rectangle, align=center, rounded corners, 
        font=\small\bfseries, inner sep=2ex, outer sep=0pt,
        fill=cyan!30, minimum height=38mm,
        on chain},
    every join/.style = arrow,
    arrow/.style = {very thick,-stealth}
    ] 
    \coordinate (tc);
    % the title
    \node[above=of tc,font=\bfseries] {PRISMA 2009 Flow Diagram};
    % the nodes at the top
    \node (n1a) [mynode, left=of tc]    {\# of records is identified 
        through database searching};
    \node (n1b) [mynode,right=of tc]    {\# of additional records indentified\\
        through other sources};
    % the chain in the center
    \node (n2)  [mynode, below=of tc]   {\# of records after duplicates removed};
    \node (n3)  [mynode,join]   {\# of additional records indentified\\
        through other sources};
    \node (n4)  [mynode,join]   {\# of full-text articles accessed 
        for eligibility};
    \node (n5)  [mynode,join]   {\# of studies included in qualitative synthesis};
    \node (n6)  [mynode,join]   {\# of studies included in quantitative sysntesis\\
        (meta-analysis)};
    % the branches to the right
    \node (n3r) [mynode,right=of n3]    {\# of records excluded};
    \node (n4r) [mynode,right=of n4]    {\# of full-text articles excluded,
        with reasons};
    % lines not included in join                                        
    \draw[arrow] ([xshift=+22mm] n1a.south) coordinate (a)
    -- (a |- n2.north);
    \draw[arrow] ([xshift=-22mm] n1b.south) coordinate (b)
    -- (b |- n2.north);
    \draw[arrow] (n3) -- (n3r);
    \draw[arrow] (n4) -- (n4r);
    % the labels on the left
    \begin{scope}[node distance=7mm]
        \node[mylabel,below left=-3mm and 11mm of n1a.north west]
        {\rotatebox{90}{Identification}};
        \node[mylabel]  {\rotatebox{90}{Screening}};
        \node[mylabel]  {\rotatebox{90}{Eligibility}};
        \node[mylabel]  {\rotatebox{90}{Included}};
    \end{scope}
\end{tikzpicture}
\captionof{figure}{\textbf{PRISMA flow chart}}

我有两个问题:

  1. 该图不适合该页面:它向右移动,因此我在左侧留有一些空间,但右侧的节点被切断了。

  2. 我为图表添加了标题,但它却显示在下一页上(也许图表的尺寸填满了整个页面。

我怎样才能将整个图形向左移动并在下方留出一些空间用于标题?

我正在使用 KOMA-skript (scrbook)

答案1

我不会费心将图像移到左边距,而是将其缩小,以便适合页面的可用空间。(以下屏幕截图中的红线代表可用的文本区域。)

在此处输入图片描述

\documentclass{scrbook}
\usepackage{tikz}
\usetikzlibrary{positioning,chains}

%%% do not include in actual document
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
%%%%%

\begin{document}

\begin{figure} % <---- added figure environment
\centering % <---- added to horizontally center the flow chart
\begin{tikzpicture}[
    node distance=15mm and 10mm,
    start chain=going below,
    mynode/.style = {
        draw, rectangle, align=center, text width=3.5cm,  % <------ replaced  5cm with 3.5cm in order to make text boxes narrow enough to fit into the page
        font=\small, inner sep=3ex, outer sep=0pt,
        on chain},
    mylabel/.style = {
        draw, rectangle, align=center, rounded corners, 
        font=\small\bfseries, inner sep=2ex, outer sep=0pt,
        fill=cyan!30, minimum height=38mm,
        on chain},
    every join/.style = arrow,
    arrow/.style = {very thick,-stealth}
    ] 
    \coordinate (tc);
    % the title
    \node[above=of tc,font=\bfseries] {PRISMA 2009 Flow Diagram};
    % the nodes at the top
    \node (n1a) [mynode, left=of tc]    {\# of records is identified 
        through database searching};
    \node (n1b) [mynode,right=of tc]    {\# of additional records indentified\\
        through other sources};
    % the chain in the center
    \node (n2)  [mynode, below=of tc]   {\# of records after duplicates removed};
    \node (n3)  [mynode,join]   {\# of additional records indentified\\
        through other sources};
    \node (n4)  [mynode,join]   {\# of full-text articles accessed 
        for eligibility};
    \node (n5)  [mynode,join]   {\# of studies included in qualitative synthesis};
    \node (n6)  [mynode,join]   {\# of studies included in quantitative sysntesis\\
        (meta-analysis)};
    % the branches to the right
    \node (n3r) [mynode,right=of n3]    {\# of records excluded};
    \node (n4r) [mynode,right=of n4]    {\# of full-text articles excluded,
        with reasons};
    % lines not included in join                                        
    \draw[arrow] ([xshift=+15mm] n1a.south) coordinate (a) % <------ replaced  22mm with 15mm to adjust the horizontal placement of the arrows
    -- (a |- n2.north);
    \draw[arrow] ([xshift=-15mm] n1b.south) coordinate (b) % <------ replaced  22mm with 15mm to adjust the horizontal placement of the arrows
    -- (b |- n2.north);
    \draw[arrow] (n3) -- (n3r);
    \draw[arrow] (n4) -- (n4r);
    % the labels on the left
    \begin{scope}[node distance=7mm]
        \node[mylabel,below left=-3mm and 4mm of n1a.north west]  % <------ replaced  11mm with 4mm to decrease the space between the blue rotated boxes and teh white boxes
        {\rotatebox{90}{Identification\vphantom{g}}}; % <--------  added \vphantom{g} for equal box widths
        \node[mylabel]  {\rotatebox{90}{Screening}};
        \node[mylabel]  {\rotatebox{90}{Eligibility}};
        \node[mylabel]  {\rotatebox{90}{Included\vphantom{g}}};  % <--------  added \vphantom{g} for equal box widths
    \end{scope}
\end{tikzpicture}
\caption{PRISMA flow chart} % <------ used \caption instead of \captionof
\end{figure}



\end{document}

相关内容