
tikz로 나란히 그려진 두 그래프의 축을 수직으로 정렬하려면 어떻게 해야 합니까? 내 코드는 다음과 같습니다.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\resizebox{0.45\linewidth}{8cm}{
\begin{tikzpicture}
\tikzstyle{every node}=[font=\tiny];
%Axes
\draw[-latex] (0, 0) -- (3, 0) ;
\draw[-latex] (0, -1.5) -- (0, 2);
\node[above] at (0, 2) {\( \$ \)};
\node[right] at (3, 0) {\( S_T \)};
%Title
\node[above, font = \small\bfseries] at (current bounding box.north) {Long Call};
\end{tikzpicture}
}
\quad
\resizebox{0.45\linewidth}{8cm}{
\begin{tikzpicture}
\tikzstyle{every node}=[font=\tiny];
%Axes
\draw[-latex] (0, 0) -- (3, 0) ;
\draw[-latex] (0, -1.5) -- (0, 2);
\node[above] at (0, 2) {\( \$ \)};
\node[right] at (3, 0) {\( S_T \)};
%Title
\node[above, font = \small\bfseries] at (current bounding box.north) {Short Call};
\end{tikzpicture}
}
\end{center}
\end{document}
아래 그림에서 볼 수 있듯이 축이 약간 잘못 정렬되어 있습니다.
문제는 'Long'의 g가 왼쪽 제목을 더 크게 만든다는 사실에서 비롯된 것 같습니다. 나는 그림과 valign = t 모두에 대해 동일한 크기 조정 치수를 정의하려고 시도했지만 둘 다 작동하지 않았습니다.
답변1
baseline
다음과 같이 동일한 좌표에 간단히 배치하세요 (0,0)
.
\begin{tikzpicture}[baseline={(0,0)}]
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\resizebox{0.45\linewidth}{8cm}{
\begin{tikzpicture}[baseline={(0,0)}]
\tikzstyle{every node}=[font=\tiny];
%Axes
\draw[-latex] (0, 0) -- (3, 0) ;
\draw[-latex] (0, -1.5) -- (0, 2);
\node[above] at (0, 2) {\( \$ \)};
\node[right] at (3, 0) {\( S_T \)};
%Title
\node[above, font = \small\bfseries] at (current bounding box.north) {Long Call};
\end{tikzpicture}
}
\quad
\resizebox{0.45\linewidth}{8cm}{
\begin{tikzpicture}[baseline={(0,0)}]
\tikzstyle{every node}=[font=\tiny];
%Axes
\draw[-latex] (0, 0) -- (3, 0) ;
\draw[-latex] (0, -1.5) -- (0, 2);
\node[above] at (0, 2) {\( \$ \)};
\node[right] at (3, 0) {\( S_T \)};
%Title
\node[above, font = \small\bfseries] at (current bounding box.north) {Short Call};
\end{tikzpicture}
}
\end{center}
\end{document}
답변2
- 이미지의 작은 수직 정렬 불일치는 제목 노드의 수직 크기가 다르기 때문에 발생합니다. 첫 번째에는 문자 g와 내림차순이 포함되어 있고 두 번째에는 이러한 문자가 없습니다. 예를 들어 텍스트 깊이를 규정하는 경우
text depth=0.5ex
두 제목 노드 모두 동일한 높이를 가지게 되고 결과적으로 두 이미지가 모두 수직으로 정렬됩니다. - 주제에서 벗어남: of를 사용하는
\resizebox
것은 좋은 생각이 아닙니다. 글꼴 크기도 변경되므로 제어할 수 없습니다.
\documentclass{article}
\usepackage{tikz}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{center}
\tikzset{
every node/.style = {text depth=0.5ex, font=\small} % <---
}
\begin{tikzpicture}
%Axes
\draw[-latex] (0, 0-0) -- (0.4\linewidth, 0) node[right] {\( S_T \)};
\draw[-latex] (0,-1.5) -- (0, 3) node[above] {\( \$ \)};
%Title
\node[above, font = \bfseries] at (current bounding box.north) {Long Call};
\end{tikzpicture}
\hfill
\begin{tikzpicture}
%Axes
\draw[-latex] (0, 0-0) -- (0.4\linewidth, 0) node[right] {\( S_T \)};
\draw[-latex] (0,-1.5) -- (0, 3) node[above] {\( \$ \)};
%Title
\node[above, font = \bfseries] at (current bounding box.north) {Short Call};
\end{tikzpicture}
\end{center}
\end{document}
(빨간색 선은 텍스트 테두리를 나타냅니다)
답변3
제목이나 캡션의 텍스트 높이가 달라 수직 정렬이 망가지는 경우에 대한 좀 더 일반적인 해결 방법은 Latex가 다른 텍스트에도 더 높은(낮은) 문자가 있는 것처럼 보이게 만드는 것입니다.
두 텍스트가 Long Call
및 인 경우 Short Call
후자를 로 변경하면 됩니다 Short Call\vphantom{g}
. 이런 식으로 Latex는 이 수직 공간도 차지하는 것으로 처리합니다(그러나 추가 수평 공간은 없음).
이것은 약간의 해킹이며 이 경우 원점을 변경하는 등 거의 항상 더 나은 솔루션이 있지만 정렬을 빠르게 수정하려는 경우 유용한 트릭입니다. Short Call\vphantom{Long Call}
확실하게 하기 위해 어떤 문자가 원인인지 알거나 추측하거나 약간 과잉을 사용하면 됩니다 .