1

Hello I have been making a drawing with Tikz and would like to set the position of this Tikz image on the beginning of the page but it seems the tikzpicture is stuck some 3 cm from the top of the page and about 4 cm to the right and the xshift and yshift commands are not working, although the rotate, xscale and yscale commands are working, also the curve i wish to shift is constructed with the "hobby" Tikz library.

Here is my code :

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}

\begin{tikzpicture}[scale =0.5,yscale=-1.1, xscale=1.2]

\draw [rotate=-12] (1.93,2.85) to [curve  through ={(4.09,2.77)..
(3.16,0.15)..(0.45,1.68)..(2.37,6.57)..(8.41,7.82)..(12.30,8.08)}]
(13.36,8.6) .. controls (14.45,8) and (15.50,7.8) .. (19.08,7.96) to
[curve  through ={(23.36,8.97)..(25.39,10.67)}] (25.22,12.77) 
.. controls (24.22,9.9) and (21.65,10.45)..(21.09,12.27) to [curve
through ={(23.46,15.72)..(27.28,12.86)..(25.40,8.13)..(21.72,6.40)..
(16.44,5.93)..(15.3,5.79)}] (14.49,5.31) .. controls (14.18,5.5) and 
(14,5.67)..(13.3,5.82) to [curve  through ={(12.4,5.92)..(8.55,5.89)..
(5.9,5.75)..(2.01,4.06)}] (1.93,2.85) ;


\end{tikzpicture}

\end{document}
  • 1
    Please add \usepackage[showframe]{geometry} to your code to see that the gaps are not as big as you may think. It is true, though, that the bounding box for these curves is not absolutely tight. – user121799 Jan 29 '19 at 22:40
  • There is a feature request for tight bounding boxes for cubic Bézier curves sourceforge.net/p/pgf/feature-requests/109, but I don't think I'll implement it. I don't really see the benefit from implementing something that complex to remedy one-off situations like this question. – Henri Menke Jan 29 '19 at 22:45
  • The shift operators have no affect on the bounding box, which controls where a normal tikz (no overlay) is placed. – John Kormylo Jan 30 '19 at 15:24
2

This issue has been discussed here at length. I agree with Henri Menke that one does not have to rewrite TikZ to get a tight bounding box. You could use the answers of this question to rectify the issue. One additional possible way out here is to base the bounding box on the points the curve runs through.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{hobby,decorations.markings}

\begin{document}
\noindent
\begin{tikzpicture}[scale =0.5,yscale=-1.1, xscale=1.2]
\begin{scope}[overlay]
\draw [rotate=-12,postaction={decorate,decoration={markings,
mark=between positions 0 and 1 step 0.005 with {\coordinate (x\pgfkeysvalueof{/pgf/decoration/mark info/sequence number});}}}] 
(1.93,2.85) to [curve  through ={(4.09,2.77)..
(3.16,0.15)..(0.45,1.68)..(2.37,6.57)..(8.41,7.82)..(12.30,8.08)}]
(13.36,8.6) .. controls (14.45,8) and (15.50,7.8) .. (19.08,7.96) to
[curve  through ={(23.36,8.97)..(25.39,10.67)}] (25.22,12.77) 
.. controls (24.22,9.9) and (21.65,10.45)..(21.09,12.27) to [curve
through ={(23.46,15.72)..(27.28,12.86)..(25.40,8.13)..(21.72,6.40)..
(16.44,5.93)..(15.3,5.79)}] (14.49,5.31) .. controls (14.18,5.5) and 
(14,5.67)..(13.3,5.82) to [curve  through ={(12.4,5.92)..(8.55,5.89)..
(5.9,5.75)..(2.01,4.06)}] (1.93,2.85) ;
\end{scope}
\path plot[variable=\i,samples at={1,...,200}] (x\i);
\end{tikzpicture}
\end{document}

enter image description here

This leaves you with the problem that the figure is too wide to fit. Note also that \noindent had a bigger impact than the above trickery to reduce the space on the left. Of course, you could rescale it to fit.

  • I don't understand what you mean by "too wide to fit", it should be only a matter of displacing the image to the left in such a way as to center it in the page, i have been trying to do so with the clip command but it seems that it doesn't draw anything that is to the left of where text begins. – Felipe Dilho Feb 8 '19 at 17:01
  • @FelipeDilho No. If you add stuff that is too wide to fit, it will overshoot on the right side of the page. You could wrap the tikzpicture into \centerline{...} but it is not good practice to have too wide stuff in the document. – user121799 Feb 8 '19 at 17:11
  • To me it seems there is enough space to fit it in the page i just have to displace it some centimeters to the left. – Felipe Dilho Feb 8 '19 at 17:21

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.