將 .tikz pgfplots 與半自訂樣式對齊

將 .tikz pgfplots 與半自訂樣式對齊

以前,我在如何在這個問題中使用可選子圖對齊和定位表格中的圖形方面得到了幫助:覆蓋輸入中的兩個 .tikz 文件

它工作得很好,但我不喜歡使用縮放選項來縮小圖表。我喜歡只指定寬度和高度,然後讓 Latex 處理字體大小。這使得文章更加一致。

因此,在建立圖表時,我給它一種允許在序言中設定批次寬度和高度的樣式,然後編輯與下面該圖表相關的各個條目。

不幸的是,使用這個系統又導致了對齊問題。似乎只有當我使用定義序言中所有條目的自訂樣式,或者當我完全不使用自訂樣式並將 .tikz 圖片中的寬度和高度設定為相同時,對齊才會保留。

完整的 MWE 來展示我的問題:

\documentclass{article}
\usepackage{graphicx,array,booktabs,pgfplots}
\pgfplotsset{compat=1.9}
\usetikzlibrary{calc}

\pgfplotsset{inTable/.style={
width=4.0cm,
height=4.0cm,
}}

\newsavebox{\mybox}
\sbox{\mybox}{
\begin{tikzpicture}
\begin{axis}[inTable,
scale only axis,
xmin=1,
xmax=500,
xlabel={A},
ymin=0.5,
ymax=1,
ylabel={A}]

\addplot [color=blue,solid,line width=1.0pt,forget plot]
  table[row sep=crcr]{
10  0.7  \\
11  0.7  \\
12  0.7  \\
};
\end{axis}
\end{tikzpicture}}

\newsavebox{\myboxB}
\sbox{\myboxB}{
\begin{tikzpicture}
\begin{axis}[inTable,
scale only axis,
xmin=1,
xmax=200,
xlabel={B},
ymin=0,
ymax=3,
ylabel={B}]

\addplot [color=blue,solid,line width=1.0pt,forget plot]
  table[row sep=crcr]{
10  0.5  \\
11  0.6  \\
12  0.7  \\
};
\end{axis}
\end{tikzpicture}}

\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{table}[htb!]
 \centering
     \begin{tabular}{P{6.5cm} P{6.5cm}}
     \toprule
      Expt1 & Expt2\\
      \cmidrule(r){1-1}\cmidrule(l){2-2}
      \begin{tikzpicture}[baseline=(a.base)]
      \node[outer sep=0pt]  (a){\usebox{\mybox}};
       %%% Change dimensions in $(a.east)+(-0.9,0cm)$
%      \node[anchor=east,outer sep=0pt] at
%               ($(a.east)+(-0.9,0cm)$){\usebox{\mybox}};
      \end{tikzpicture}
      {\usebox{\mybox}}
      &
      {\usebox{\mybox}}
      {\usebox{\myboxB}}
      \\ \bottomrule
      \end{tabular}
      \caption{Test}
      \label{tbl:1}
\end{table}

\end{document}

錯位

非常感謝您的幫忙。這應該是我的表格-圖形-插圖繪製協議的最後一部分。

答案1

好的,謝謝 Torbjørn T,這本手冊喚醒了我的記憶。

首先,左上角的圖片其實是環境{tikzpicture}內部\begin{tikzpicture}。我必須對右上角的圖片做同樣的事情。然後將對齊標誌新增[baseline, trim axis left, trim axis right]至每個\begin{tikzpicture}(我從實際文件中的 .tikz 檔案匯入的對齊標誌),修復對齊。

最後,我有了一種對圖和子圖進行完全對齊和控制的方法。感謝所有幫助過我的人。

完整的MEW:

\documentclass{article}
\usepackage{graphicx,array,booktabs,pgfplots}
\pgfplotsset{compat=1.9}
\usetikzlibrary{calc}

\pgfplotsset{inTable/.style={
width=4.0cm,
height=4.0cm, %Change these numbers to ovveride all graphs in the table sizes in the table
}}

\newsavebox{\mybox}
\sbox{\mybox}{
\begin{tikzpicture}[baseline, trim axis left, trim axis right]
\begin{axis}[inTable,
scale only axis,
baseline,
xmin=1,
xmax=500,
xlabel={A},
ymin=0.5,
ymax=1,
ylabel={A}]

\addplot [color=blue,solid,line width=1.0pt,forget plot]
  table[row sep=crcr]{
10  0.7  \\
11  0.7  \\
12  0.7  \\
};
\end{axis}
\end{tikzpicture}}

\newsavebox{\myboxB}
\sbox{\myboxB}{
\begin{tikzpicture}[baseline, trim axis left, trim axis right]
\begin{axis}[inTable,
scale only axis,
xmin=1,
xmax=200,
xlabel={B},
ymin=0,
ymax=3,
ylabel={B}]

\addplot [color=blue,solid,line width=1.0pt,forget plot]
  table[row sep=crcr]{
10  0.5  \\
11  0.6  \\
12  0.7  \\
};
\end{axis}
\end{tikzpicture}}

\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{table}[htb!]
 \centering
     \begin{tabular}{P{6.5cm} P{6.5cm}}
     \toprule
      Expt1 & Expt2\\
      \cmidrule(r){1-1}\cmidrule(l){2-2}
      \begin{tikzpicture}[baseline=(a.base)]
      \node[outer sep=0pt]  (a){\usebox{\mybox}};
       %%% Change dimensions in $(a.east)+(-0.9,0cm)$
%      \node[anchor=east,outer sep=0pt] at
%               ($(a.east)+(-0.9,0cm)$){\usebox{\mybox}};
      \end{tikzpicture}
      {\usebox{\mybox}}
      &
      \begin{tikzpicture}[baseline=(a.base)]
      \node[outer sep=0pt]  (a){\usebox{\mybox}};
       %%% Change dimensions in $(a.east)+(-0.9,0cm)$
%      \node[anchor=east,outer sep=0pt] at
%               ($(a.east)+(-0.9,0cm)$){\usebox{\mybox}};
      \end{tikzpicture}
      {\usebox{\myboxB}}
      \\ \bottomrule
      \end{tabular}
      \caption{Test}
      \label{tbl:1}
\end{table}

\end{document}

相關內容