Fixing Picture Placement Below Margin

Click For Summary

Discussion Overview

The discussion centers around the placement of a picture created using TikZ in LaTeX, specifically addressing an issue where the picture is rendered 2 inches below the margin. Participants explore the cause of this positioning and seek solutions to adjust the placement of a node labeled "z" within the picture.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant notes that the picture is rendered below the margin due to the inclusion of the $z$ node, which affects the overall bounding box of the TikZ picture.
  • Another participant points out that the command \draw -- node {$z$} (0,2.5in) causes the node "z" to be placed at the midpoint of the line, resulting in additional white space above it.
  • Some participants discuss the implications of using the \path command without drawing options, indicating that it enlarges the area of the picture without rendering visible elements.
  • There are suggestions to modify the drawing command to adjust the placement of "z" directly at the desired point, which could eliminate the extra space above.
  • One participant expresses confusion about the placement issue and seeks further clarification on how to specify the node's position correctly.
  • Another participant explains that placing the node after a point rather than between commands can help position it accurately, and mentions the use of options like [above] to control placement.

Areas of Agreement / Disagreement

Participants generally agree on the mechanics of how TikZ commands affect node placement, but there remains some uncertainty regarding the best practices for achieving the desired visual outcome without excess space.

Contextual Notes

Limitations include potential misunderstandings of TikZ command behavior and the specific effects of node placement on the bounding box of the picture.

Dustinsfl
Messages
2,217
Reaction score
5
This picture is on a blank piece of paper but is rendered 2in below the margin. Why is this happening? I want it to be at the top of page right below the margin.
The $z$ node is causing the problem. If I remove the $z$ node, the picture moves back to the top. What can I do about this?
Code:
\begin{center}
\begin{tikzpicture}[scale = 1.25]
\draw (0,0) -- (0,3);
\draw (0,0) -- (2.5,0);
\draw (0,0) -- (-1,-1.7);
\draw (-1.5,0) arc (180:360:1.5cm and .5cm);
\draw[dashed] (-1.5,0) arc (180:0:1.5cm and .5cm);
\draw (-1.5,0) -- (-1.5,2);
\draw (1.5,0) -- (1.5,2);
\draw (-1.5,2) arc (180:360:1.5cm and .5cm);
\draw (-1.5,2) arc (180:0:1.5cm and .5cm);
\draw -- node {$y$} (2.1in,0);
\draw -- node {$z$} (0,2.5in);
\draw -- node {$x$} (-.86in,-1.5in);
\end{tikzpicture}
\end{center}
 
Last edited:
Physics news on Phys.org
As you can see there is huge gap from where the 1in margin is to the start of the tikz picture
View attachment 544
 

Attachments

  • tikzissue.jpg
    tikzissue.jpg
    8.8 KB · Views: 118
dwsmith said:
Code:
\draw (0,0) -- (0,3);
...
\draw -- node {$z$} (0,2.5in);
This is a strange way to write "z". I did not know it is possible to omit the first point in the \draw command. Apparently, the second \draw command above is equivalent to

Code:
\path (0,0) -- node {$z$} (0,2.5in);

The command \path without options does not draw anything. "The only effect is that the area occupied by the picture is (possibly) enlarged so that the path fits inside the area. To actually “do” something with the path, an option like draw or fill must be given somewhere on the path" (TikZ 2.10 manual, chapter 14). The command \draw is a contraction for \path[draw].

Next, by default when "node" is specified before the second point, the node is placed midway on the line (section 16.9). So what happens is the picture is enlarged to encompass the point (0,2.5in), but "z" is drawn only at (0,1.25in).
 
Evgeny.Makarov said:
This is a strange way to write "z". I did not know it is possible to omit the first point in the \draw command. Apparently, the second \draw command above is equivalent to

Code:
\path (0,0) -- node {$z$} (0,2.5in);

The command \path without options does not draw anything. "The only effect is that the area occupied by the picture is (possibly) enlarged so that the path fits inside the area. To actually “do” something with the path, an option like draw or fill must be given somewhere on the path" (TikZ 2.10 manual, chapter 14). The command \draw is a contraction for \path[draw].

Next, by default when "node" is specified before the second point, the node is placed midway on the line (section 16.9). So what happens is the picture is enlarged to encompass the point (0,2.5in), but "z" is drawn only at (0,1.25in).

I am confused. What is going wrong?
 
Because of the instruction

\draw -- node {$z$} (0,2.5in);

your picture includes the point (0,2.5in), but "z" is drawn at (0,1.25in). Thus, there is 1.25in of white space above (the center of) "z". You can see this if you add the line

\draw (current bounding box.north west) rectangle (current bounding box.south east);

before "\end{tikzpicture}". You can also replace

\draw -- node {$z$} (0,2.5in);

with

\draw (0,0) -- node {$z$} (0,2.5in);

to see that the top end of the line lies on the top edge of the bounding box and "z" is directly in the middle of that line.
 
Evgeny.Makarov said:
Because of the instruction

\draw -- node {$z$} (0,2.5in);

your picture includes the point (0,2.5in), but "z" is drawn at (0,1.25in). Thus, there is 1.25in of white space above (the center of) "z". You can see this if you add the line

\draw (current bounding box.north west) rectangle (current bounding box.south east);

before "\end{tikzpicture}". You can also replace

\draw -- node {$z$} (0,2.5in);

with

\draw (0,0) -- node {$z$} (0,2.5in);

to see that the top end of the line lies on the top edge of the bounding box and "z" is directly in the middle of that line.

Ok I understand. I had to adjust as such to get z in the correct place though. How else can I specify it?
 
dwsmith said:
Ok I understand. I had to adjust as such to get z in the correct place though. How else can I specify it?
Yes, I should have said this earlier. When "node {...}" is placed not between "--" and a point, but after a point, then the node is placed at that point. You can also specify options like [above] after "node". So, you can get the same result, but without the extra space above if you replace

Code:
\draw (0,0) -- (0,3);

with

Code:
\draw (0,0) -- (0,3) node[above] {$z$};

This is described in sections "Placing nodes on a curve explicitly" and "Placing nodes on a curve implicitly" (or something like that) in the manual.
 

Similar threads

Replies
2
Views
2K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • Poll Poll
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K