
이 MWE에서 tikzpicture
상위 부동 환경( figure
또는 subfigure
)의 할당된 공간을 어떻게 맞출 수 있습니까?
\RequirePackage{luatex85}
\documentclass{article}
\usepackage{pgfplots,caption,subcaption,mwe}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}
\begin{subfigure}[t]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}
편집하다
아래 코드의 출력은 \textwidth
각 하위 그림 너비를 0.33\textwidth
.
\begin{figure}
\centering
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}
\end{subfigure}
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\lipsum[1]
답변1
세 번째 하위 그림을 별도의 줄에 표시하는 이유는 하위 그림 사이에 공백이 있기 때문입니다. 코드의 줄 바꿈은 공백과 동일하므로 %
after 가 필요합니다 \end{subfigure}
. 즉, 대신
\end{subfigure}
%
\begin..
당신은 필요
\end{subfigure}%
%
\begin..
또는
\end{subfigure}%
\begin..
예를 참조하십시오%
줄 끝에 백분율 기호( )를 사용하는 방법은 무엇입니까 ?
두 번째 문제는 width
a의 키가 pgfplots
axis
실제로 정확하지 않다는 것입니다. pgfplots
눈금 레이블과 축 레이블이 축 자체 외부의 45pt 공간을 차지한다고 가정하는 것입니다 . 따라서 지정된 너비를 사용하여 45pt를 빼고 이 너비를 축에 사용합니다.
45pt를 다른 것으로 변경할 수는 없지만 자신만의 축 너비를 계산할 수 있으며 키를 사용하여 매개변수가 눈금 라벨/축 라벨을 무시하고 축에 적용된다고 scale only axis
말할 수 있습니다.width
더 조잡한 방법은 전체를 tikzpicture
에 넣고 \resizebox
간단히 하위 그림의 너비에 맞게 크기를 조정하는 것입니다. 문제는 글꼴 크기도 조정된다는 것입니다.
마지막으로, 이에 대한 캡션이 없으면 환경은 subfigure
다소 무의미하며 폐기될 수 있습니다.
첫 번째 행은 의 효과를 보여줍니다 \resizebox
. 두 번째 행에서는 계산된 축 너비를 사용했고 세 번째 행에서는 동일하지만 subfigure
환경은 사용하지 않았습니다. 패키지 showframe
는 텍스트 영역 주위에 프레임을 인쇄합니다. 이는 스크린샷에 표시된 줄입니다.
\RequirePackage{luatex85}
\documentclass{article}
\usepackage{pgfplots,subcaption,showframe}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.33\textwidth}
\resizebox{\textwidth}{!}{\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\resizebox{\textwidth}{!}{\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\resizebox{\textwidth}{!}{\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\textwidth]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}}
\end{subfigure}
\pgfmathsetlengthmacro{\myaxiswidth}{0.33\textwidth-width(" 150 ")}% subtract width of widest ticklabel, with a space on each side
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}
\end{subfigure}%
%
\begin{subfigure}[t]{0.33\textwidth}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-a};
\end{axis}
\end{tikzpicture}%
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-b};
\end{axis}
\end{tikzpicture}%
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=\myaxiswidth,scale only axis]
\addplot graphics [
xmin=0,
xmax=50,
ymin=0,
ymax=150,
] {example-image-c};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}