# How to centre the picture position horizontally?

I am drawing pictures in picture-mode with commands. The code example is below:

\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\oddsidemargin 0mm
\oddsidemargin 0mm
\textheight 234mm \textwidth 154mm

\columnsep 8 mm \topmargin -15  mm

\begin{document}

{\unitlength 0.75pt
\begin{picture}(400,140)
\put(100,20){\circle{20}}
\put(150,20){\circle{20}}
\put(110,20){\line(1,0){30}}
\put(100,70){\circle{20}}
\put(100,30){\line(0,1){30}}
\put(157,27){\line(1,1){36}}
\put(200,70){\circle{20}}
\put(107,27){\line(1,1){36}}
\put(150,70){\circle{20}}
\put(107,77){\line(1,1){36}}
\put(150,120){\circle{20}}
\put(93,77){\line(-1,1){36}}
\put(50,120){\circle{20}}
\put(100,120){\circle{20}}
\put(100,80){\line(0,1){30}}
\end{picture}
}

\end{document}


The output is:

Question. How to centre the picture position horizontally?

## 2 Answers

I use showframe package to show the margin box. If you draw the frame box of your picture, you will see a large empty space on the right. Because you set you picture boundary like \begin{picture}(400,140). As you see in the first picture, use \centering before the pitcture env, the whole picture env is already centered however you actual drawing are not centered because the empty space. The second picture is centered properly because the boundary is set properly according to the drawing geometry. There are more advanced drawing packages are available such as tikz. You should use try to use them.

\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\oddsidemargin 0mm
\oddsidemargin 0mm
\textheight 234mm \textwidth 154mm

\columnsep 8 mm \topmargin -15  mm
\usepackage{showframe} %show margin box

\begin{document}
{\centering
\fbox{\unitlength 0.75pt
\begin{picture}(400,140)
\put(100,20){\circle{20}}
\put(150,20){\circle{20}}
\put(110,20){\line(1,0){30}}
\put(100,70){\circle{20}}
\put(100,30){\line(0,1){30}}
\put(157,27){\line(1,1){36}}
\put(200,70){\circle{20}}
\put(107,27){\line(1,1){36}}
\put(150,70){\circle{20}}
\put(107,77){\line(1,1){36}}
\put(150,120){\circle{20}}
\put(93,77){\line(-1,1){36}}
\put(50,120){\circle{20}}
\put(100,120){\circle{20}}
\put(100,80){\line(0,1){30}}
\end{picture}
}\par}

{\centering
\fbox{\unitlength 0.75pt
\begin{picture}(250,140)
\put(100,20){\circle{20}}
\put(150,20){\circle{20}}
\put(110,20){\line(1,0){30}}
\put(100,70){\circle{20}}
\put(100,30){\line(0,1){30}}
\put(157,27){\line(1,1){36}}
\put(200,70){\circle{20}}
\put(107,27){\line(1,1){36}}
\put(150,70){\circle{20}}
\put(107,77){\line(1,1){36}}
\put(150,120){\circle{20}}
\put(93,77){\line(-1,1){36}}
\put(50,120){\circle{20}}
\put(100,120){\circle{20}}
\put(100,80){\line(0,1){30}}
\end{picture}
}\par}

\end{document}


• Your solution works for me. Is it possible to automatizate the the picture processing? Because I have a lot of such objects.
– Nick
Jun 24 at 6:49
• @Nick Sorry, I don't think there is way. At least I don't know. You may ask a another question.
– Tom
Jun 24 at 7:08
• oh, you are from rare people who still use picture, a legacy of early LaTeX version :-)
• Using it you need manually calculate image position so that it is positioned at page center. For example by shifting your image for 120 pt to the right:
\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\oddsidemargin 0mm
\oddsidemargin 0mm
\textheight 234mm \textwidth 154mm

\columnsep 8 mm \topmargin -15  mm

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\hspace{120pt}{\unitlength 0.75pt
\begin{picture}(400,140)
\put(100,20){\circle{20}}
\put(150,20){\circle{20}}
\put(110,20){\line(1,0){30}}
\put(100,70){\circle{20}}
\put(100,30){\line(0,1){30}}
\put(157,27){\line(1,1){36}}
\put(200,70){\circle{20}}
\put(107,27){\line(1,1){36}}
\put(150,70){\circle{20}}
\put(107,77){\line(1,1){36}}
\put(150,120){\circle{20}}
\put(93,77){\line(-1,1){36}}
\put(50,120){\circle{20}}
\put(100,120){\circle{20}}
\put(100,80){\line(0,1){30}}
\end{picture}
}
\end{document}

• Far more simple is to use tikz package and system of relative coordinates and insert tikzpicture in center environment:

\documentclass[a4paper,12pt]{article}
\usepackage[hmargin=28mm,vmargin=31mm,
columnsep=8mm]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage[english]{babel}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}[
node distance = 50pt,
C/.style = {circle, draw, minimum size=20pt,
node contents={}}
]
\node (c1) [C];
\node (c2) [C, right of=c1];
\node (c3) [C, right of=c2];
%
\node (c4) [C, below of=c2];
\node (c5) [C, right of=c4];
\node (c6) [C, right of=c5];
%
\node (c7) [C, below of=c4];
\node (c8) [C, right of=c7];
%%
\draw   (c1) -- (c4) -- (c7) -- (c7) -- (c8) -- (c6)
(c2) -- (c4)
(c3) -- (c4)
(c5) -- (c7);
\end{tikzpicture}
\end{center}
\end{document}


As you see, for above solution you not need to calculate position of image elements coordinates or amount for shift of image or define appropriate image bounding box.

• Yes, I have a lot of such objects that were done with picture.
– Nick
Jun 24 at 6:50
• @Nick, this is no excuse. If at all picture you need to correct position of image, is simple to redraw them. But you the best know, what is bet to you. And your decision you not need to justify to me :-) Jun 24 at 7:52
• @Zarko I fixed one typo, but I'm not sure what you mean by ar above, so I left that. Jun 24 at 7:53
• @daleif, thank you. It should be for above. Iwill corRect this ASAP Jun 24 at 7:55