tikz 그림 사이의 공간을 제거합니다.

tikz 그림 사이의 공간을 제거합니다.

다음 MWE

\documentclass{article}
\usepackage{tikz}
\begin{document}
\noindent{}\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}\\
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}
\end{document}

생산하다

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

다음과 같이 공백을 제거할 수 있다는 것을 알고 있습니다.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\noindent{}\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}\hspace*{-0.3em}
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}\\[-1pt]
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}\hspace*{-0.3em}
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}
\end{document}

하지만 이렇게 하려면 간격을 수동으로 미세 조정해야 하고 오류가 발생하기 쉬운 것 같습니다. 그림 사이의 공백(가로 및 세로 모두)을 자동으로 제거하는 방법이 있습니까?

답변1

tabular적절하게 설정된 매개변수와 함께 를 사용할 수 있습니다 .

\documentclass{article}
\usepackage{tikz}

\newenvironment{pics}
 {\par\raggedright % maybe \centering
  \setlength\tabcolsep{0pt}\renewcommand{\arraystretch}{0}%
  \begin{tabular}{*{10}c}}
 {\end{tabular}\par}

\begin{document}

\begin{pics}
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} \\
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}
\end{pics}

\bigskip

\begin{pics}
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} \\
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture} &
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}
\end{pics}

\end{document}

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

답변2

수평 간격은 Andrew의 설명에 의해 설명됩니다.논평: 환경 사이에 줄 단위의 공백이 끝납니다.

그림이 기준선 건너뛰기보다 크기 때문에 TeX는 레지스터를 사용하여 \lineskip수직 방향으로 상자를 구분합니다.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\noindent
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}%
\begin{tikzpicture}\fill [red] (0,0) rectangle(1,1);\end{tikzpicture}%
\\[-\lineskip]
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}%
\begin{tikzpicture}\fill [red] (0,0) rectangle (1,1);\end{tikzpicture}%
\end{document}

결과

관련 정보