以下 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}