如何正确定位 tikzpicture?

如何正确定位 tikzpicture?

% 我需要知道如何让这个 tikzpicture 保持居中。它往往会向左和向右移动。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[paperheight=14in,paperwidth=8.5in,margin=2in,heightrounded]{geometry}
\usepackage{geometry}
\usepackage{tikz}
\usepackage{amsfonts, amsmath, amsthm, amssymb} \usepackage[utf8]{inputenc}
\usepackage{dtklogos}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{mindmap,trees,shadows}
\usetikzlibrary{positioning,shapes,shadows, arrows}
\begin{document}
\thispagestyle{empty}
\hspace{-4.5cm}
\begin{minipage}[t]{1.20\linewidth}
\raggedright
\vspace{-4.0cm}
\Large\textbf{Where Are We Now?}\\% Title
\today
\end{minipage}

\centering
\begin{tikzpicture}[auto, node distance = 0.36cm, thick, every node/.style = {rectangle, minimum width= 34mm, rounded corners=2pt, font = \sffamily, black,top color = green!40!white, bottom color = green!20!white,drop shadow, minimum height = 0.5cm}]
\node[minimum height=0.3cm] (SWGDAM){\sffamily\bfseries{SWGDAM Guidelines for Validation of Probabilistic Genotyping Systems}};
\node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.15cm, minimum height=0cm, minimum size=0.1cm] right:{\scriptsize4.2}}] (42)        [below = of SWGDAM, xshift=3cm, yshift=0cm]  {Comparative Study};
\node[label={[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.1cm, minimum height=0cm, minimum size=0.1cm] right:{\scriptsize4.1}}] (41)[below = of 42, xshift=0cm, yshift=0cm]  {Data Generation}; 
\node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.1cm, minimum height=0cm, minimum size=0.2cm] right:{\scriptsize4.2.1}}]  (421)        [below = of 41] {Consistency};
 \node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.1cm, minimum height=0cm, minimum size=0.25cm] right:{\scriptsize4.2.1.1}}] (4211)   [below  = of 421, top color=yellow, bottom color=yellow]        {Method Comparison};
\node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.1cm, minimum height=0cm, minimum size=0.25cm] right:{\scriptsize4.2.1.2}}] (4212)   [below  = of 4211, top color=yellow, bottom color=yellow]        {Concordance};
 \node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.15cm, minimum height=0cm, minimum size=0.1cm] right:{\scriptsize7}}] (intval)        [below = of SWGDAM, xshift=-2.0cm, yshift=-0.36cm, top color=gray!40!white, bottom color=gray!40!white]  {\bfseries{Internal Validation}};
\node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.15cm, minimum height=0cm, minimum size=0.1cm] right:{\scriptsize7.1.1}}] (711b)        [below = of intval, xshift=0cm, yshift=0cm, top color=gray!20!white, bottom color=white]  {Template Concentration}; 
 \node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.15cm, minimum height=0cm, minimum size=0.1cm] right:{\scriptsize7.1.2}}] (712b)        [below = of 711b, xshift=0cm, yshift=0cm, top color=gray!20!white, bottom color=white]  {Mixture Proportions};
 \node[label= {[circle,  text width=0.25cm, top color=white, bottom color=white, yshift=0.17cm, xshift=-0.15cm, minimum height=0cm, minimum size=0.1cm] right:{\scriptsize3333}}] (3333)        [left = of intval, xshift=-1cm, yshift=0cm, top color=gray!20!white, bottom color=white]  {3333};
\end{tikzpicture}
 \end{document}

答案1

要查看图像大小与文档文本宽度的比较,请将选项添加showframe到包的选项中geometry

正如其他人已经指出的那样,图像太宽了。他们还提出了一些解决方案,即如何通过后处理来减少图像宽度。在这个想法中,使用的想法resizebox存在严重的缺陷:减少图像也会减少字体大小。可能会发生字体变得太小而难以阅读的情况。

对于采取的任何措施,以更清晰的形式重新编码图像是适当的,使用通用的样式定义,这比最终重新设计表格更容易操作(在我看来这是唯一正确的方法)。关于可能的代码重新设计,以下是 MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe,
            paperheight=14in,paperwidth=8.5in,
            margin=2in,heightrounded]{geometry}
%\usepackage{geometry}
%\usepackage{tikz}
\usepackage{amsfonts, amsmath, amsthm, amssymb} 
\usepackage[utf8]{inputenc}
%\usepackage{dtklogos}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows}
\begin{document}
\thispagestyle{empty}
\hspace{-4.5cm}
\begin{minipage}[t]{1.20\linewidth}
\raggedright
\vspace{-4.0cm}
\Large\textbf{Where Are We Now?}\\
\today
\end{minipage}

\centering
\begin{tikzpicture}[%auto, thick, 
node distance = 3.6mm and 9mm, 
C/.style args = {#1/#2}{% Color
    top color = #1, bottom color=#2},
C/.default = green!40!white/green!20!white,
     N/.style = {% Node
    rectangle, rounded corners=2pt,  
    minimum width= 31mm, font = \sffamily\footnotesize, %black,
    drop shadow, minimum height = 5mm}, 
every label/.style = {shape=circle, fill=white, text width=4.5ex, align=center,
           inner sep=1pt, font=\sffamily\scriptsize, drop shadow,
           yshift=0.17cm, xshift=-0.15cm}
                                          ]
\node [N,C] (SWGDAM)    {\textbf{SWGDAM Guidelines for Validation 
                                 of Probabilistic Genotyping Systems}};
\node [N,C,label=right:4.2,
       below left=5mm and 0mm of SWGDAM.south east]     
                                            (42)    {Comparative Study};
\node[N,C,label=right:4.1,below=of 42]      (41)    {Data Generation};
\node[N,C,label=right:4.2.1,below=of 41]    (421)   {Consistency};
\node[N,C=yellow/yellow,
      label=right:4.2.1.1, below=of 421]   (4211)   {Method Comparison};
\node[N,C=yellow/yellow,
      label=right:4.2.1.2, below=of 4211]   (4212)  {Concordance};
\node[N,C=gray!40!white/gray!40!white, 
      label=right:7, left = of 42]      (intval)    {\textbf{Internal Validation}};
\node[N,C=gray!20!white/white,
      label=right:7.1.1,below = of intval]  (711b)  {Template Concentration};
 \node[N,C=gray!20!white/white,
       label=right:7.1.2,below = of 711b]   (712b)  {Mixture Proportions};
\node[N,C=gray!20!white/white,
      label=right:3333,left = of intval]    (3333)  {3333};
\end{tikzpicture}
    \end{document}

这使:

在此处输入图片描述

无论使用何种\footnotesize字体大小,图像都比文本宽度宽。解决方案似乎是考虑将节点中的文本分成两行:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe,
            paperheight=14in,paperwidth=8.5in,
            margin=2in,heightrounded]{geometry}
\usepackage{amsfonts, amsmath, amsthm, amssymb} 
\usepackage[utf8]{inputenc}
%\usepackage{dtklogos} % not relevant
\usepackage{tikz}
\usetikzlibrary{positioning,shadows}
\begin{document}
\thispagestyle{empty}
\hspace{-4.5cm}
\begin{minipage}[t]{1.20\linewidth}
\raggedright
\vspace{-4.0cm}
\Large\textbf{Where Are We Now?}\\% Title
\today
\end{minipage}

\centering
\begin{tikzpicture}[%auto, thick, 
node distance = 3.6mm and 9mm, 
C/.style args = {#1/#2}{% Color
    top color = #1, bottom color=#2},
   C/.default = green!40!white/green!20!white,
     N/.style = {% Node
    rectangle, rounded corners=2pt, 
    minimum width= 24mm, font = \sffamily, 
    align=center, inner xsep=1ex,
    drop shadow, minimum height = 5mm}, 
every label/.style = {shape=circle, fill=white, text width=4.5ex, align=center,
           inner sep=1pt, font=\sffamily\scriptsize, drop shadow,
           yshift=0.17cm, xshift=-0.15cm}
                                          ]
\node [N,C,font=\bfseries\sffamily] (SWGDAM)   {SWGDAM Guidelines for Validation of\\
                                                Probabilistic Genotyping Systems};
\node [N,C,label=right:4.2,
       below=of SWGDAM.south east]     
                                            (42)    {Comparative\\ Study};
\node[N,C,label=right:4.1,below=of 42]      (41)    {Data\\ Generation};
\node[N,C,label=right:4.2.1,below=of 41]    (421)   {Consistency};
\node[N,C=yellow/yellow,
      label=right:4.2.1.1, below=of 421]   (4211)   {Method\\ Comparison};
\node[N,C=yellow/yellow,
      label=right:4.2.1.2, below=of 4211]   (4212)  {Concordance};
%
\node[N,C=gray!40!white/gray!40!white,font=\bfseries\sffamily,
      label=right:7, below = of SWGDAM]     (intval)    {Internal\\ Validation};
\node[N,C=gray!20!white/white,
      label=right:7.1.1,below = of intval]  (711b)  {Template\\ Concentration};
 \node[N,C=gray!20!white/white,
       label=right:7.1.2,below = of 711b]   (712b)  {Mixture\\ Proportions};
%
\node[N,C=gray!20!white/white,
      label=right:3333,below = of SWGDAM.south west]   (3333)  {3333};
\end{tikzpicture}
    \end{document}

在此处输入图片描述

答案2

正如评论中提到的那样,图片比边距更宽。

要了解边距是否溢出,请启用类选项draft

\documentclass[draft]{article}

这样,如果有东西超出边缘,您会在边缘看到一个黑条指示它。

要正确对齐它,有多种选择:

1.调整绘图

使用 tikz 键scale、、、xy...使图形变小

2. 使用 resizebox 缩放绘图

将您的tikzpicture环境包裹在一个调整大小的盒子中:

\resizebox{\linewidth}{!}{\begin{tikzpicture} ... \end{tikzpicture}}

表示\linewidth目标宽度(请注意,如果图像的宽度小于该宽度,它将被放大!),同时!计算高度以保持比例。

3. 让绘图对称地溢出边距

这是通过告诉 LaTeX 你的绘图宽度为其中心 0pt 来实现的,这可以通过将环境包装tikzpicturemakebox

\makebox[0pt][c]{\begin{tikzpicture} ... \end{tikzpicture}}

相关内容