tikz 的 \matrix 中的數字之間的間距

tikz 的 \matrix 中的數字之間的間距

我試著將 4 個高度不等的數字放入一個矩陣中。我的程式碼你可以編譯這裡是:

\documentclass[journal=aamick]{achemso}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\title{hi}
\begin{document}
\maketitle
\newlength{\w}
\setlength{\w}{.9\paperwidth}

\noindent \begin{tikzpicture}[align=center]

\matrix[column sep=.0\w,row sep=.0\w,%
every node/.style={draw,node distance=0 and 0,outer sep=0},xshift=-.048\w]{
\node [label=above:(a)] (a)  {\includegraphics[width=.14\w]{figs/16_4.jpeg}}; & 
\node [label=right:(d)] (d)  {\includegraphics[width=.14\w]{figs/16_10.jpeg}};\\
\node [label=below:(b)] (b)  {\includegraphics[width=.14\w]{figs/8_4.jpeg}}; &
\node [label=right:(c)] (c)  {\includegraphics[width=.14\w]{figs/8_10.pdf}};\\};

\end{tikzpicture}%

\end{document}

我得到的是:

左側框之間有一個間隙(紅色箭頭)。我想要的是這樣的:

我怎樣才能做到這一點?

答案1

您只需要適當地設定錨點,即添加

row 1/.style={anchor=south},row 2/.style={anchor=north}

到矩陣的選項。

\documentclass[journal=aamick]{achemso}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\title{hi}
\begin{document}
\maketitle
\newlength{\w}
\setlength{\w}{.9\paperwidth}

\noindent \begin{tikzpicture}[align=center]
\matrix[column sep=.0\w,row sep=.0\w,%
every node/.style={draw,outer sep=0},
row 1/.style={anchor=south},row 2/.style={anchor=north}]{
\node [label=above:(a)] (a)  {\includegraphics[width=.14\w]{example-image-duck}}; & 
\node [label=right:(d)] (d)  {\includegraphics[width=.14\w,height=.14\w]{example-image-duck}};\\
\node [label=below:(b)] (b)  {\includegraphics[width=.14\w]{example-image-duck}}; &
\node [label=right:(c)] (c)  {\includegraphics[width=.14\w,height=.14\w]{example-image-duck}};\\};

\end{tikzpicture}%

\end{document}

在此輸入影像描述

我沒有你的圖形文件,所以我使用一些標準文件,但具有不同的有效高度來模擬你的問題。

附錄:您可以使用以下方法節省一些按鍵操作

\setkeys{Gin}{width=.14\w}

從那時起,該組中包含的所有圖形的寬度都將具有此寬度。 Alsonodes是 的縮寫every node/.append style,並且 node distance=0 and 0,沒有任何作用,,xshift=-.048\w只要tikzpicture只由該矩陣組成也沒有任何作用。

\documentclass[journal=aamick]{achemso}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\title{hi}
\begin{document}
\maketitle
\newlength{\w}
\setlength{\w}{.9\paperwidth}

\noindent \begin{tikzpicture}[align=center]
\setkeys{Gin}{width=.14\w}
\matrix[column sep=.0\w,row sep=.0\w,%
nodes={draw,outer sep=0},
row 1/.style={anchor=south},row 2/.style={anchor=north}]{
\node [label=above:(a)] (a)  {\includegraphics{example-image-duck}}; & 
\node [label=right:(d)] (d)  {\includegraphics[height=.14\w]{example-image-duck}};\\
\node [label=below:(b)] (b)  {\includegraphics{example-image-duck}}; &
\node [label=right:(c)] (c)  {\includegraphics[height=.14\w]{example-image-duck}};\\};

\end{tikzpicture}%
\end{document}

相關內容