这是一些应该运行的代码,
\documentclass{article}
\usepackage{amsthm}
\usepackage{tikz}
\begin{document}
\noindent\textbf{Identity 1.} \textit{For $n \geq 2$,}
\[
{\color{blue} {n \choose 2}} + {\color{red} {{n+1} \choose 2} } \ = \ n^2.
\]
\begin{proof}
\begin{center}
\begin{tikzpicture}[baseline=(current bounding box.north)]
\foreach \x in {0,...,8} {%
\foreach \y in {0,...,\x} {%
\filldraw[red] (0.5*\x,0.5*\y) circle (2pt);
}%
}%
\foreach \x in {0,...,7} {%
\foreach \y in {0,...,\x} {%
\filldraw[blue] (3.5-0.5*\x,4-0.5*\y) circle (2pt);
}%
}%
\draw[|-|,red] (0,-0.5) -- (4,-0.5) node[midway,below] {$n$};
\draw[|-|,red] (4.5,0) -- (4.5,4) node[midway,right] {$n$};
\draw[|-|,blue] (0,4.5) -- (3.5,4.5) node[midway,above] {$n-1$};
\draw[|-|,blue] (-0.5,0.5) -- (-0.5,4) node[midway,left] {$n-1$};
\end{tikzpicture}
\end{center}
\end{proof}
\end{document}
这是其产生的结果。
如您所见,开头的“证明。”没有左对齐,这让我很困扰。我该如何解决这个问题?
答案1
\documentclass{article}
\usepackage{amsthm}
\usepackage{tikz}
\begin{document}
\noindent\textbf{Identity 1.} \textit{For $n \geq 2$,}
\[
{\color{blue} {n \choose 2}} + {\color{red} {{n+1} \choose 2} } \ = \ n^2.
\]
\begin{proof} \hspace{2cm}
% \begin{center}
\begin{tikzpicture}[baseline=(current bounding box.north)]
\foreach \x in {0,...,8} {%
\foreach \y in {0,...,\x} {%
\filldraw[red] (0.5*\x,0.5*\y) circle (2pt);
}%
}%
\foreach \x in {0,...,7} {%
\foreach \y in {0,...,\x} {%
\filldraw[blue] (3.5-0.5*\x,4-0.5*\y) circle (2pt);
}%
}%
\draw[|-|,red] (0,-0.5) -- (4,-0.5) node[midway,below] {$n$};
\draw[|-|,red] (4.5,0) -- (4.5,4) node[midway,right] {$n$};
\draw[|-|,blue] (0,4.5) -- (3.5,4.5) node[midway,above] {$n-1$};
\draw[|-|,blue] (-0.5,0.5) -- (-0.5,4) node[midway,left] {$n-1$};
\end{tikzpicture}
% \end{center}
\end{proof}
\end{document}
答案2
我会使用\hfill
而不是center
环境并观察到~\par
用作证明文本。还请删除该[baseline=..]
,以便 QED 标记出现在 tikzpicture 之后。
\documentclass{article}
\usepackage{amsthm}
\usepackage{tikz}
\begin{document}
\noindent\textbf{Identity 1.} \textit{For $n \geq 2$,}
\[
{\color{blue} {n \choose 2}} + {\color{red} {{n+1} \choose 2} } \ = \ n^2.
\]
\begin{proof}~\par
\hfill % <---
\begin{tikzpicture}%[baseline=(current bounding box.north)] % <---
\foreach \x in {0,...,8} {%
\foreach \y in {0,...,\x} {%
\filldraw[red] (0.5*\x,0.5*\y) circle (2pt);
}%
}%
\foreach \x in {0,...,7} {%
\foreach \y in {0,...,\x} {%
\filldraw[blue] (3.5-0.5*\x,4-0.5*\y) circle (2pt);
}%
}%
\draw[|-|,red] (0,-0.5) -- (4,-0.5) node[midway,below] {$n$};
\draw[|-|,red] (4.5,0) -- (4.5,4) node[midway,right] {$n$};
\draw[|-|,blue] (0,4.5) -- (3.5,4.5) node[midway,above] {$n-1$};
\draw[|-|,blue] (-0.5,0.5) -- (-0.5,4) node[midway,left] {$n-1$};
\end{tikzpicture}
\hfill % <---
\end{proof}
\end{document}
答案3
使用补丁并正确使用包amsthm
,\newtheorem
你将获得:
\documentclass{article}
\usepackage{amsthm}
\usepackage{tikz}
\newtheorem{id}{Identity}
%%%%%%%%%%%%%%%%
\usepackage{xpatch}
\xpatchcmd{\proof}{\hskip\labelsep}{\hskip-2\labelsep}{}{} %% https://tex.stackexchange.com/questions/235735/indent-the-word-proof-in-environment-proof-of-amsthm
%%%%%%%%%%%%%%%%
\begin{document}
\begin{id}
For $n \geq 2$,
\[
{\color{blue} {n \choose 2}} + {\color{red} {{n+1} \choose 2} } \ = \ n^2.
\]
\begin{proof}
\begin{center}
\begin{tikzpicture}[baseline=(current bounding box.north)]
\foreach \x in {0,...,8} {%
\foreach \y in {0,...,\x} {%
\filldraw[red] (0.5*\x,0.5*\y) circle (2pt);
}%
}%
\foreach \x in {0,...,7} {%
\foreach \y in {0,...,\x} {%
\filldraw[blue] (3.5-0.5*\x,4-0.5*\y) circle (2pt);
}%
}%
\draw[|-|,red] (0,-0.5) -- (4,-0.5) node[midway,below] {$n$};
\draw[|-|,red] (4.5,0) -- (4.5,4) node[midway,right] {$n$};
\draw[|-|,blue] (0,4.5) -- (3.5,4.5) node[midway,above] {$n-1$};
\draw[|-|,blue] (-0.5,0.5) -- (-0.5,4) node[midway,left] {$n-1$};
\end{tikzpicture}
\end{center}
\end{proof}
\end{id}
\end{document}
你可以左移证明再次减少负值\hskip-2
。