
Следующий 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
Горизонтальные зазоры объясняются Эндрюкомментарий: Пробелы по концам строк между средами.
Поскольку размеры изображений превышают базовый пропуск строки, 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}