11

I am new to tikz and trying to learn how to use it to draw a full page cover page for a report I am writing. I have successfully changed the margins and can render to the full page, but I am struggling to understand how I can draw rectangles at fixed absolute locations from the bottom on the page. I want to put tabulars into the rectangle nodes to display name blocks over the water mark image.

So my question is how can I draw the blue and red nodes on my page at absolute locations? Also can I specify the height ( say 4cm) of the node (rectangle) and center the tabluar vertically in that rectangle?

In my code all I can see in the blue rectangle at the top.

        \documentclass[a4paper,12pt]{article}
        \usepackage{tikz}
        \usepackage[left=5.2cm,top=2cm,right=1.5cm,bottom=2cm,verbose,nohead,nofoot]{geometry}
        \usepackage{etoolbox}

        % Set up full page to draw in 

        \AfterEndEnvironment{myfullpage}{\restoregeometry}
        \newenvironment{myfullpage}{%
            \newgeometry{left=0cm,top=0cm,right=0cm,bottom=0cm,nohead,nofoot}%
        }{%
            \newpage%
        }

        \begin{document}
        \begin{myfullpage}
            \begin{tikzpicture}[remember picture,overlay,shift={(current page.south west)}]
                %\node [inner sep=0pt,above right] {\includegraphics[width=\paperwidth]{matrix.eps}};

                % Draw a full page width filled rectangle with tabular over at bottom of page 

                \begin{tikzpicture}[remember picture,overlay, anchor = west]
                    \node (names) [shape=rectangle,fill=blue,minimum width =\paperwidth] {
                        \begin{tabular}{r l}
                            A & B
                        \end{tabular}
                    };
                \end{tikzpicture}

                % Draw a full page width filled rectangle with tabular over 8 cm from page current page.south west

                \begin{tikzpicture}[remember picture,overlay, shift={(0 cm, 8cm)}, anchor=west]
                    \node (names) [shape=rectangle,fill=red,minimum width =\paperwidth] {
                    \begin{tabular}{r l}
                            one & two
                    \end{tabular}
                    };
                \end{tikzpicture}

            \end{tikzpicture}
        \end{myfullpage}
        \end{document} 
  • It's important to mention that \usepackage{tikz} must stay before \usepackage{geometry}! – yegor256 Jun 28 '16 at 1:13
5

Something like this?

full width rectangles

Note that nesting tikzpictures should be avoided if at all possible as it is known to cause problems.

There is no need to change the geometry here: we can just use absolute coordinates relative to the page itself e.g. (current page.center) for positioning:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage[left=5.2cm,top=2cm,right=1.5cm,bottom=2cm,verbose,nohead,nofoot]{geometry}
\usepackage{etoolbox}

\begin{document}
  \thispagestyle{empty}
  \begin{tikzpicture}[remember picture,overlay]
      \node (back names) [shape=rectangle, fill=blue, minimum height=40mm, minimum width=\paperwidth, anchor=south west] at (current page.south west) {};
      \node at (back names.center) {
        \begin{tabular}{r l}
          A & B
        \end{tabular}
      };
      \node (names) [shape=rectangle, fill=red, minimum width=\paperwidth, anchor=west] at ([yshift=8cm]current page.south west) {
        \begin{tabular}{r l}
          one & two
        \end{tabular}
      };
  \end{tikzpicture}
\end{document}

The tabular is most easily centred by drawing it after the blue rectangle with a center anchor.

Note that there is not much point in naming two nodes names. If you need to refer to the nodes, they need unique names. If not, they don't need names at all.

4

It can be done with proper choice of anchors (current page ) & some shifts:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage[left=5.2cm,top=2cm,right=1.5cm,bottom=2cm,verbose,nohead,nofoot]{geometry}

\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay, anchor = west]
 \node[fill=blue,anchor=north,minimum height=4cm, minimum width=\paperwidth] (names)
   at ([yshift=4cm]current page.south) {
    \begin{tabular}{r l}
        A & B
    \end{tabular}
    };


 \node[fill=red,anchor=south, minimum width=\paperwidth] (names)
   at ([yshift=8cm]current page.south) {
    \begin{tabular}{r l}
        one & two
    \end{tabular}
    };
\end{tikzpicture}

\end{document}

enter image description here

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.