2

Here is some code that should run,

\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}

and here is what it produces.

As you can see, the "Proof." at the beginning is not left aligned, which is bothering me. How can I fix that?

2
  • 1
    the center command will shift everything to center-- so remove that --now you have left alignment--to give space add hspace of 2cm--you can experiment --see the answer below
    – js bibra
    Commented Jul 18, 2020 at 8:49
  • 1
    I’m voting to close this question because too specific.
    – henry
    Commented Jul 18, 2020 at 9:09

3 Answers 3

1

enter image description here

\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}
1

I would use \hfill instead of center environment and observe that ~\par used as proof text. Also remove that [baseline=..], for the QED mark to appear after the 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}

enter image description here

1
  • 1
    I thinked below "For" the word "Proof" :-(. Very nice.
    – Sebastiano
    Commented Jul 18, 2020 at 9:22
0

Using xpatch and using correctly the package amsthm, putting \newtheorem you will have:

\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}

enter image description here

You can shift left Proof again decrease the negative value \hskip-2.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .