对齐 \includestandalone{} 图表

对齐 \includestandalone{} 图表

我有两个大小相同的独立条形图,但是当我\includestandalone{}将它们插入到我的主文档中时,我无论如何也无法让它们对齐。

如果我将它们放在同一个独立文档中并以此方式导入,它们就完全一致了。但它们是两个独立的图形,我希望能够将它们作为独立的实体进行控制。我可以做些什么来使其更整齐?

我知道这只是一件很小的事,但 a) 看起来很粗心。并且 b) 整个想法是将它们完美地堆叠起来,以便读者可以比较和对比这两组。


在这里,它们被包含在一个独立的文档中,完美对齐:

条形图.tex 在此处输入图片描述


在这里,它们被包含在两个单独的独立文档中,彼此不协作:

条形图1.tex+条形图2.tex

在此处输入图片描述


以下是独立的条形图代码:

条形图.tex

\documentclass[margin=10,tikz]{standalone}
\usepackage{tikz}
\tikzset{barlabels/.style={font=\footnotesize\sffamily}, 
declare function={barheight=5pt;}}

\begin{document}
\begin{tikzpicture}[y=0.3cm, x=0.06cm]
\begin{scope}[yshift=-0cm]
\foreach [count=\i from 0] \p/\t in{
    500/Marriott (2018),
    3000/Yahoo! (2017),
    143/Equifax (2017),
    412/FriendFinder (2016),
    145/eBay (2014),
    110/Target (2013)}
{\node [anchor=base east, barlabels, name=i-\i] at (0,-\i) {\t};
\fill [blue!40] (i-\i.base east) rectangle ++({(1*(\p)/25)*0.6},barheight) ++(0,-barheight) node[barlabels, black, anchor=base west] {\p\ M};
}
\end{scope}
\begin{scope}[yshift=-2cm]
\foreach [count=\i from 0] \p/\t in{
    110/Target (2013),
    38/Adobe (2013),
    77/Sony (2011),
    40/RSA Security (2011),
    134/Heartland (2008),
    94/TJX (2006)}
{\node [anchor=base east, barlabels, name=i-\i] at (0,-\i) {\t};
\fill [red!50] (i-\i.base east) rectangle ++({((\p)-13)*0.6},barheight) ++(0,-barheight) node[barlabels, black, anchor=base west] {\p\ M};
}
\end{scope}
\end{tikzpicture}
\end{document}

它们分别如下:

条形图1.tex

\documentclass[margin=10,tikz]{standalone}
\usepackage{tikz}
\tikzset{barlabels/.style={font=\footnotesize\sffamily}, 
declare function={barheight=5pt;}}

\begin{document}
\begin{tikzpicture}[y=0.3cm, x=0.05cm]
\begin{scope}[yshift=-4cm]
\foreach [count=\i from 0] \p/\t in{
    500/Marriott (2018),
    3000/Yahoo! (2017),
    143/Equifax (2017),
    412/FriendFinder (2016),
    145/eBay (2014),
    110/Target (2013)}
{\node [anchor=base east, barlabels, name=i-\i] at (0,-\i) {\t};
\fill [blue!40] (i-\i.base east) rectangle ++({(1*(\p)/25)*0.6},barheight) ++(0,-barheight) node[barlabels, black, anchor=base west] {\p\ M};
}
\end{scope}
\end{tikzpicture}
\end{document}

条形图2.tex

\documentclass[margin=10,tikz]{standalone}
\usepackage{tikz}
\tikzset{barlabels/.style={font=\footnotesize\sffamily}, 
declare function={barheight=5pt;}}

\begin{document}
\begin{tikzpicture}[y=0.3cm, x=0.05cm]
\begin{scope}[yshift=-4cm]
\foreach [count=\i from 0] \p/\t in{
    110/Target (2013),
    38/Adobe (2013),
    77/Sony (2011),
    40/RSA Security (2011),
    134/Heartland (2008),
    94/TJX (2006)}
{\node [anchor=base east, barlabels, name=i-\i] at (0,-\i) {\t};
\fill [red!50] (i-\i.base east) rectangle ++({((\p)-13)*0.6},barheight) ++(0,-barheight) node[barlabels, black, anchor=base west] {\p\ M};
}
\end{scope}
\end{tikzpicture}
\end{document}

主文本

这是 main.tex 文档的 MWE:

\documentclass[apacite,jou,a4paper]{apa6}
\usepackage{amsmath,amssymb,booktabs}  
\usepackage[table,xcdraw]{xcolor}
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{tikz}
\tikzset{barlabels/.style={font=\footnotesize\sffamily}, 
declare function={barheight=5pt;}}
\usepackage{standalone}

\title{Title}

\begin{document}
\maketitle    

\section{Heading}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\\

\noindent
\centering
\includestandalone{test/bargraph1}
\\
\noindent
\centering
\includestandalone{test/bargraph2}
\\

\section{Heading}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \\

\bibliography{references}

\end{document}

答案1

这将创建两个具有共同左边框和右边框的 tikzpicture。我首先打印每个 tikzpicture 的边框,然后取两者中较大(更极端)的边框。右边框会影响缩放或居中。

\documentclass[tikz]{standalone}
\tikzset{barlabels/.style={font=\footnotesize\sffamily}, 
declare function={barheight=5pt;}}

\newcommand{\printborder}{% must be run inside a tikzpicture
  \path (current bounding box.south west);
  \pgfgetlastxy{\west}{\south}
  \path (current bounding box.north east);
  \pgfgetlastxy{\east}{\north}
  \node[above] at (current bounding box.north) {(\west, \south) (\east, \north)};
}

\begin{document}
\begin{tikzpicture}[y=0.3cm, x=0.06cm]
\foreach [count=\i from 0] \p/\t in{
    500/Marriott (2018),
    3000/Yahoo! (2017),
    143/Equifax (2017),
    412/FriendFinder (2016),
    145/eBay (2014),
    110/Target (2013)}
{\node [anchor=base east, barlabels, name=i-\i] at (0,-\i) {\t};
\fill [blue!40] (i-\i.base east) rectangle ++({(1*(\p)/25)*0.6},barheight) ++(0,-barheight) node[barlabels, black, anchor=base west] {\p\ M};
}
%\printborder
\path (-81pt,0) (158pt,0);% set common west and east borders
\end{tikzpicture}

\begin{tikzpicture}[y=0.3cm, x=0.06cm]
\foreach [count=\i from 0] \p/\t in{
    110/Target (2013),
    38/Adobe (2013),
    77/Sony (2011),
    40/RSA Security (2011),
    134/Heartland (2008),
    94/TJX (2006)}
{\node [anchor=base east, barlabels, name=i-\i] at (0,-\i) {\t};
\fill [red!50] (i-\i.base east) rectangle ++({((\p)-13)*0.6},barheight) ++(0,-barheight) node[barlabels, black, anchor=base west] {\p\ M};
}
%\printborder
\path (-81pt,0) (158pt,0);% set common west and east borders
\end{tikzpicture}
\end{document}

相关内容