tikzpicture 위의 수직 공간을 제거하십시오.

tikzpicture 위의 수직 공간을 제거하십시오.

두 개의 tikzpicture를 나란히 배치하려고 하는데 왼쪽 사진 위에 수직 공간이 생깁니다! 공간을 제거하는 방법을 아시나요?

\begin{tikzpicture}
\draw [solid] (0,0) -- (0,6);
\draw [solid] (0,0) -- (6.6,0);
\draw [solid] (0,5.5) -- (0.5,5.5);
\draw [solid] (0,3.5) -- (3,3.5);
\draw [solid] (0.5,2) -- (0.5,5.5);
\draw [solid] (0.5,2) -- (4,2);
\draw [solid] (3,.7) -- (3,3.5);
\draw [solid] (3,.7) -- (6.5,.7);
\draw [solid] (4,0) -- (4,2);
\draw [solid] (6.5,0) -- (6.5,.7);
% draw vertical lines
\foreach \x in {0,0.5,3,4,6.5}
\draw (\x cm,3pt) -- (\x cm,-3pt);
\foreach \x/\descr in {0/0,0.5/C_1,3/C_2,4/C_3, 6.5/C_4}
\node[font=\scriptsize, text height=1.75ex,
text depth=.5ex] at (\x,-.3) {$\descr$};
\node[text width=3cm, anchor=west, right] at (-0.1,3.7){$p_1$};
\node[text width=3cm, anchor=west, right] at (-0.7,4.5){$w_1$};
\node[text width=3cm, anchor=west, right] at (-0.1,2.7){$w_2$};
\node[text width=3cm, anchor=west, right] at (1.2,2.2){$p_2$};
\node[text width=3cm, anchor=west, right] at (2.3,1.3){$w_3$};
\node[text width=3cm, anchor=west, right] at (3.1,0.9){$p_3$};
\node[text width=3cm, anchor=west, right] at (3.35,0.36){$w_4$};
\node[text width=3cm, anchor=west, right] at (4.8,0.18){$p_4$};
\end{tikzpicture}
\begin{tikzpicture}
\draw[color=red!20, line width=13.6pt] 
(1.25,3.52) -- (1.25,5.49);
\draw[color=yellow!40, line width=85pt] 
(2.5,2.01) -- (2.5,3.49);
\draw[color=green!35, line width=113pt] 
(3,0.71) -- (3,1.99);
\draw[color=blue!25, line width=184.5pt] 
(4.247,0) -- (4.247,0.7);
\draw [solid] (1,0) -- (1,6);
\draw [solid] (1,0) -- (8.3,0);
\draw [solid] (1,5.5) -- (1.5,5.5);
\draw [solid] (1,3.5) -- (4,3.5);
\draw [solid] (1.5,2) -- (1.5,5.5);
\draw [solid] (1,2) -- (5,2);
\draw [solid] (4,.7) -- (4,3.5);
\draw [solid] (1,.7) -- (7.5,.7);
\draw [solid] (5,0) -- (5,2);
\draw [solid] (7.5,0) -- (7.5,.7);
% draw vertical lines
\foreach \x in {1,1.5,4,5,7.5}
\draw (\x cm,3pt) -- (\x cm,-3pt);
\foreach \x/\descr in {1/0,1.5/C_1,4/C_2,5/C_3, 7.5/C_4}
\node[font=\scriptsize, text height=1.75ex,
text depth=.5ex] at (\x,-.3) {$\descr$};
\node[text width=3cm, anchor=west, right] at (0.9,3.7){$p_1$};
\node[text width=3cm, anchor=west, right] at (0.3,4.5){$w_1$};
\node[text width=3cm, anchor=west, right] at (0.3,2.7){$w_2$};
\node[text width=3cm, anchor=west, right] at (2.2,2.2){$p_2$};
\node[text width=3cm, anchor=west, right] at (0.3,1.3){$w_3$};
\node[text width=3cm, anchor=west, right] at (4.1,0.9){$p_3$};
\node[text width=3cm, anchor=west, right] at (0.3,0.36){$w_4$};
\node[text width=3cm, anchor=west, right] at (5.8,0.18){$p_4$};
\end{tikzpicture}

여기에 이미지 설명을 입력하세요

답변1

제가 댓글에서 말했듯이 여기서 문제는 로 선을 그릴 때 line width=X경계 상자가 각 선의 끝을 넘어 X/2만큼 확장된다는 것입니다. 그래서 당신이 할 때

\draw[color=blue!25, line width=184.5pt]  (4.247,0) -- (4.247,0.7);

해당 선의 경계 상자는 y=0 아래로 92.25pt 확장됩니다. 다이어그램의 윤곽을 그리기 위해 추가하면 \draw (current bounding box.south east) rectangle (current bounding box.north west);오른쪽 다이어그램에 공백이 많이 있음을 알 수 있습니다.

와 같이 색상이 지정된 직사각형을 그리는 데 다른 기술을 사용하는 것 외에 \fill[blue!25] (1,0) rectangle +(184.5pt, 0.7);가장 간단한 수정은 아마도 overlay해당 선에 옵션을 추가하는 것입니다.

\draw[color=blue!25, line width=184.5pt, overlay] (4.247,0) -- (4.247,0.7);

경로에 추가 하면 overlay경계 상자를 계산할 때 해당 경로가 고려되지 않습니다.

관련 정보