我有以下代码:
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{tikzpicture}
\matrix (A) [column sep=0pt, row sep=0pt]
{\node[inner sep=0pt](A-1-1){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-c}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image}};\\
\node[inner sep=0pt](A-2-1){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-c}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-a}};\\
\node[inner sep=0pt](A-3-1){\includegraphics[width=2cm, height=2cm]{example-image-c}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-b}};\\
\node[inner sep=0pt](A-4-1){\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt](A-4-2){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt](A-4-3){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt](A-4-4){\includegraphics[width=2cm, height=2cm]{example-image-c}};\\
\node[inner sep=0pt](A-5-1){\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt](A-5-2){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt](A-5-3){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt](A-5-4){\includegraphics[width=2cm, height=2cm]{example-image-c}};\\
\node[inner sep=0pt](A-6-1){\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt](A-6-2){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt](A-6-3){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt](A-6-4){\includegraphics[width=2cm, height=2cm]{example-image-c}};\\
};
\node[right=1mm of A, minimum size=8cm] (B)
{\includegraphics[width=8cm,height=12cm]{example-image-a}};
\node[below left =1mm of B.north east, minimum size=3cm] (C)
{\includegraphics[width=3cm,height=3cm]{example-image-b}};
\draw[->,very thick, shorten >=-2mm] (A.south west) --
(A.south-|B.east) node[midway, below=8mm] {Time};
\draw[->,very thick, shorten >=-2mm] (A.south west) --
(A.north west) node[midway, left=10mm,rotate=90]{Quantity};
\foreach \i [evaluate=\i as \t using int(1*\i),
evaluate=\i as \j using int(5-\i)] in {1,2,3,4}{
\node [below=43mm of A-4-\i] {\t};
\node [left=5mm of A-\i-1] {\j};}
\end{tikzpicture}
\end {document}
我在运行此代码时遇到两个问题;首先,我向此代码添加了两行,但无法添加标签或指示每个新行的值(如您在结果图中所见),另一件事是我想将 x 轴的值更改为(0,0.5,1,2)而不是(1,2,3,4),并将 y 轴的值更改为(1,10,50,100,250,500)而不是旧值。(见附图)
答案1
我想最简单的方法就是把它分成两个循环并明确指定标签,即
\foreach \i/\t in {1/0,2/0.5,3/1,4/2}
\node [below=43mm of A-4-\i] {\t};
\foreach \j/\t in {1/500, 2/250, 3/100, 4/50, 5/10, 6/1}
\node [left=5mm of A-\j-1] {\t};
而不是\foreach
你现在所拥有的。
通过使用matrix of nodes
,并设置图像的默认大小,您可以稍微减少代码:
\documentclass[tikz,border=20mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{tikzpicture}
\setkeys{Gin}{width=2cm,height=2cm} % sets default size of images within the tikzpicture
\matrix (A) [column sep=0pt, row sep=0pt,matrix of nodes,nodes={inner sep=0pt}]
{\includegraphics{example-image-a}&
\includegraphics{example-image-b}&
\includegraphics{example-image-c}&
\includegraphics{example-image}\\
\includegraphics{example-image-b}&
\includegraphics{example-image-c}&
\includegraphics{example-image}&
\includegraphics{example-image-a}\\
\includegraphics{example-image-c}&
\includegraphics{example-image}&
\includegraphics{example-image-a}&
\includegraphics{example-image-b}\\
\includegraphics{example-image}&
\includegraphics{example-image-a}&
\includegraphics{example-image-b}&
\includegraphics{example-image-c}\\
\includegraphics{example-image}&
\includegraphics{example-image-a}&
\includegraphics{example-image-b}&
\includegraphics{example-image-c}\\
\includegraphics{example-image}&
\includegraphics{example-image-a}&
\includegraphics{example-image-b}&
\includegraphics{example-image-c}\\
};
\node[right=1mm of A, minimum size=8cm] (B)
{\includegraphics[width=8cm,height=12cm]{example-image-a}};
\node[below left =1mm of B.north east, minimum size=3cm] (C)
{\includegraphics[width=3cm,height=3cm]{example-image-b}};
\draw[->,very thick, shorten >=-2mm] (A.south west) --
(A.south-|B.east) node[midway, below=8mm] {Time};
\draw[->,very thick, shorten >=-2mm] (A.south west) --
(A.north west) node[rotate=90,midway, left=13mm]{Quantity};
\foreach \i/\t in {1/0,2/0.5,3/1,4/2}
\node [below=43mm of A-4-\i] {\t};
\foreach \j/\t in {1/500, 2/250, 3/100, 4/50, 5/10, 6/1}
\node [left=5mm of A-\j-1] {\t};
\end{tikzpicture}
\end {document}
原始代码
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{tikzpicture}
\matrix (A) [column sep=0pt, row sep=0pt]
{\node[inner sep=0pt](A-1-1){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-c}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image}};\\
\node[inner sep=0pt](A-2-1){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-c}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-a}};\\
\node[inner sep=0pt](A-3-1){\includegraphics[width=2cm, height=2cm]{example-image-c}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt]{\includegraphics[width=2cm, height=2cm]{example-image-b}};\\
\node[inner sep=0pt](A-4-1){\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt](A-4-2){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt](A-4-3){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt](A-4-4){\includegraphics[width=2cm, height=2cm]{example-image-c}};\\
\node[inner sep=0pt](A-5-1){\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt](A-5-2){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt](A-5-3){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt](A-5-4){\includegraphics[width=2cm, height=2cm]{example-image-c}};\\
\node[inner sep=0pt](A-6-1){\includegraphics[width=2cm, height=2cm]{example-image}};&
\node[inner sep=0pt](A-6-2){\includegraphics[width=2cm, height=2cm]{example-image-a}};&
\node[inner sep=0pt](A-6-3){\includegraphics[width=2cm, height=2cm]{example-image-b}};&
\node[inner sep=0pt](A-6-4){\includegraphics[width=2cm, height=2cm]{example-image-c}};\\
};
\node[right=1mm of A, minimum size=8cm] (B)
{\includegraphics[width=8cm,height=12cm]{example-image-a}};
\node[below left =1mm of B.north east, minimum size=3cm] (C)
{\includegraphics[width=3cm,height=3cm]{example-image-b}};
\draw[->,very thick, shorten >=-2mm] (A.south west) --
(A.south-|B.east) node[midway, below=8mm] {Time};
\draw[->,very thick, shorten >=-2mm] (A.south west) --
(A.north west) node[midway, left=13mm,rotate=90]{Quantity};
\foreach \i/\t in {1/0,2/0.5,3/1,4/2}
\node [below=43mm of A-4-\i] {\t};
\foreach \j/\t in {1/500, 2/250, 3/100, 4/50, 5/10, 6/1}
\node [left=5mm of A-\j-1] {\t};
\end{tikzpicture}
\end {document}