3

I am trying to draw a simple rectangle and position it on the bottom of the page. So as I am pretty new to tikz, I am not quite sure how to it. Lets say I want it to look like this hard coded triangle:

\tikz \fill[blue] (3,3) -- (18, 3) -- (19,4) -- cycle;

Now, I found information that I need to use nodes to get coordinates relative to the page. SO I have to define nodes, and store the coordinates, right?

\node (A) at (current page.south west) {};
\node (B) at (current page.south east) {};
\coordinate (cA) at (A) ;
\coordinate (cB) at (B);

So know my problem is, that I don't know how to specify the third coordinates, as they are not relative to the page. What I want for example is, that the triangle has a "height" of given length (lets say 2 cm...)

\draw[line width=1mm] (cA) -- (cB) -- (??) -- cycle;
  • Welcome! Can you please complete your snippets to something we can compile? Can you explain what the role of this figure is? Is it content you want to put in a figure, say? Is it a footer? is it something that should be background, behind the text? – cfr Jul 29 '18 at 23:18
4

The key insight you are missing is that to specify relative coordinates you can use ++. For example, from (current page.south east) if you want to draw a line 2 cm up from this point, simply write (current page.south east)--++(0,2cm). This means, move 2cm in the y direction from the previous coordinate, with no change in the x direction.

To get back across the page to coordinate 2cm above (current page.south west) I've used the -| command, which tells TikZ to find the right angle intersection point between the two coordinates. Note there is an opposite version of this called |- which would in this case return the coordinate (current page.south east).

So all in all, the path you want for this rectangle is (current page.south west) -- (current page.south east) --++(0,2cm) -| (current page.south west) -- cycle. So in one exercise you've now learnt two really useful drawing commands in TikZ. There are of course a number of other ways to do it, one of which is using rectangle as shown in John Kormylo's answer.

Additionally, If you want this 'footer' to appear on every page, then you can use something like this.

I've put the TikZ code in a command I've named \Footer and then used the package atbegshi as described in TikZ header and footer across top and bottom of bulletin/newsletter page.

enter image description here

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{atbegshi}

\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill [remember picture,overlay,blue] (current page.south west) -- (current page.south east) --++(0,2cm) -| (current page.south west) -- cycle;
\end{tikzpicture}%
}

\pagestyle{empty}
\AtBeginShipout{\Footer}
\AtBeginShipoutFirst{\Footer}

\begin{document}

\blindtext[6]

\end{document}
| improve this answer | |
  • Ok thanks, I think I understood now the relative to coordinate information. I also like your suggestion if I want to put it on every page. But another question here - Is it also possible to do it by using tikz and the background setups?? – beginner_of_beginner Aug 1 '18 at 11:30
  • I haven't got an answer for that. But by all means go ahead and write a new question on the site. – Milo Aug 1 '18 at 11:47
5

Don't forget to run it twice. Note: tikzpagenodes will give you access to the location of the header, footer, text and marginpar areas.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikz[remember picture, overlay] \fill[blue] (current page.south west) rectangle ++(\paperwidth,2cm);
\end{document}
| improve this answer | |

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.