2

I am having problems with centering my picture in a LaTeX document. I want to center the following picture:

\documentclass[10pt]{article}
\usepackage{pgf,tikz,geometry}
\geometry{a4paper}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle     45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-4.3,0.) -- (18.24,0.);
\foreach \x in {-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.,-5.46) -- (0.,6.3);
\foreach \y in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.3,-5.46) rectangle (18.24,6.3);
\fill[color=zzttqq,fill=zzttqq,fill opacity=0.1] (5.02,4.58) -- (1.14,-1.68) -- (10.16,-1.64) -- cycle;
\draw [color=zzttqq] (5.02,4.58)-- (1.14,-1.68);
\draw [color=zzttqq] (1.14,-1.68)-- (10.16,-1.64);
\draw [color=zzttqq] (10.16,-1.64)-- (5.02,4.58);
\draw (5.02,4.58)-- (5.444270493230518,-1.6609123259723702);
\draw (1.14,-1.68)-- (7.330385094078737,1.784164341406664);
\draw (10.16,-1.64)-- (3.1879758358533326,1.6242084361963565);
\begin{scriptsize}
\draw [fill=qqqqff] (5.02,4.58) circle (1.5pt);
\draw[color=qqqqff] (5.16,4.86) node {$A$};
\draw [fill=qqqqff] (1.14,-1.68) circle (1.5pt);
\draw[color=qqqqff] (1.08,-1.92) node {$B$};
\draw [fill=qqqqff] (10.16,-1.64) circle (1.5pt);
\draw[color=qqqqff] (10.3,-1.36) node {$C$};
\draw [fill=qqqqff] (5.287774051225104,0.6411110045818896) circle (1.5pt);
\draw[color=qqqqff] (5.14,0.4) node {$I$};
\draw [fill=qqqqff] (3.1879758358533326,1.6242084361963565) circle (1.5pt);
\draw[color=qqqqff] (2.82,1.58) node {$E$};
\draw [fill=qqqqff] (5.444270493230518,-1.6609123259723702) circle (1.5pt);
\draw[color=qqqqff] (5.62,-1.82) node {$D$};
\draw [fill=qqqqff] (7.330385094078737,1.784164341406664) circle (1.5pt);
\draw[color=qqqqff] (7.64,1.74) node {$F$};
\draw[color=black] (4.96,1.6) node {$g$};
\draw[color=black] (4.44,-0.06) node {$h$};
\draw[color=black] (6.86,0.46) node {$i$};
\end{scriptsize}
\end{tikzpicture}
\end{document}

Can anyone help me by pointing out how to center this picture (with its caption)? The \centering command is not working.

Note:- By "centering" I want to mean an analogous operation to the text centering which can be achieved by using \begin{center}...\end{center} or by $\text{}$.

3

It will centre if you make it small enough to fit on the page (I added scale=.5 ) and add \centering and \end{document}

enter image description here

\documentclass[10pt]{article}
\usepackage{pgf,tikz,geometry}
\geometry{a4paper}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\centering


X\dotfill X

\bigskip


\definecolor{zzttqq}{rgb}{0.6,0.2,0.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle       45,x=1.0cm,y=1.0cm,scale=.5]
\draw[->,color=black] (-4.3,0.) -- (18.24,0.);
\foreach \x in   {-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.,-5.46) -- (0.,6.3);
\foreach \y in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.3,-5.46) rectangle (18.24,6.3);
\fill[color=zzttqq,fill=zzttqq,fill opacity=0.1] (5.02,4.58) -- (1.14,-1.68) -- (10.16,-1.64) -- cycle;
\draw [color=zzttqq] (5.02,4.58)-- (1.14,-1.68);
\draw [color=zzttqq] (1.14,-1.68)-- (10.16,-1.64);
\draw [color=zzttqq] (10.16,-1.64)-- (5.02,4.58);
\draw (5.02,4.58)-- (5.444270493230518,-1.6609123259723702);
\draw (1.14,-1.68)-- (7.330385094078737,1.784164341406664);
\draw (10.16,-1.64)-- (3.1879758358533326,1.6242084361963565);
\begin{scriptsize}
\draw [fill=qqqqff] (5.02,4.58) circle (1.5pt);
\draw[color=qqqqff] (5.16,4.86) node {$A$};
\draw [fill=qqqqff] (1.14,-1.68) circle (1.5pt);
\draw[color=qqqqff] (1.08,-1.92) node {$B$};
\draw [fill=qqqqff] (10.16,-1.64) circle (1.5pt);
\draw[color=qqqqff] (10.3,-1.36) node {$C$};
\draw [fill=qqqqff] (5.287774051225104,0.6411110045818896) circle (1.5pt);
\draw[color=qqqqff] (5.14,0.4) node {$I$};
\draw [fill=qqqqff] (3.1879758358533326,1.6242084361963565) circle (1.5pt);
\draw[color=qqqqff] (2.82,1.58) node {$E$};
\draw [fill=qqqqff] (5.444270493230518,-1.6609123259723702) circle (1.5pt);
\draw[color=qqqqff] (5.62,-1.82) node {$D$};
\draw [fill=qqqqff] (7.330385094078737,1.784164341406664) circle (1.5pt);
\draw[color=qqqqff] (7.64,1.74) node {$F$};
\draw[color=black] (4.96,1.6) node {$g$};
\draw[color=black] (4.44,-0.06) node {$h$};
\draw[color=black] (6.86,0.46) node {$i$};
\end{scriptsize}
\end{tikzpicture}

\end{document}
  • Is it possible to "center" the document without affecting its size? – user 170039 Jun 24 '15 at 13:04
  • @user170039 not sure what you mean by doesn't work, did you try it as posted above? I added a picture to show the centred output. – David Carlisle Jun 24 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.