# How positioning works with tikz

I am back again with my table.

I've added a tikz picture on the right side. I am quite happy with the result but I don't truly understand what I've done since I copied some code from here and tweaked it a little bit.

Here is the code:

\documentclass{letter}

\usepackage[a4paper, margin=15pt]{geometry}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\newlength{\Oldarrayrulewidth}
\newcommand{\Cline}[2]{%
\noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
\noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
\noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}}

\newcommand\VRule{\vrule width 2pt}

\multicolumn{1}{|c}{\textbf{#2}} &
\multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{#1}}}
}

\newcommand\mottonScoreEmptyCells{%
& \multicolumn{1}{c!{\VRule}}{} & & & & & & & & & & & & & & &\\
}

\newcommand\mottonScoreBorder{%
\cline{4-4} \cline{7-7} \cline{10-10} \cline{13-13} \cline{16-16}
}

\newcommand\mottonScoreEmptyDoubleCells{%
\multicolumn{1}{|c}{} & \multicolumn{1}{|c|}{} & \multicolumn{1}{|c!{\VRule}}{} & & \multicolumn{2}{c!{\VRule}}{} & & \multicolumn{2}{c!{\VRule}}{} & & \multicolumn{2}{c!{\VRule}}{} & & \multicolumn{2}{c!{\VRule}}{} & & \multicolumn{2}{c!{\VRule}}{}\\
}

\newcommand\mottonScoreRow[2]{%
}

\newcommand\mottonScore{%
\setlength{\extrarowheight}{2pt}
\begin{tabularx}{\textwidth}{ccp{15pt}|*{5}{p{8pt}|X@{+}p{15pt}!{\VRule}}}
\cline{4-18}

& & & \multicolumn{15}{c|}{\textbf{Joueurs}} \\ \cline{4-18}

& & \multicolumn{1}{c!{\VRule}}{} & \multicolumn{3}{c!{\VRule}}{} & \multicolumn{3}{c!{\VRule}}{} & \multicolumn{3}{c!{\VRule}}{} & \multicolumn{3}{c!{\VRule}}{} & \multicolumn{3}{c!{\VRule}}{} \\ \cline{1-18}

\mottonScoreRow{10}{\multirow{40}{*}{\rotatebox[origin=c]{90}{Cartes}}}\cline{2-18}
\mottonScoreRow{9}{}\cline{2-18}
\mottonScoreRow{8}{}\cline{2-18}
\mottonScoreRow{7}{}\cline{2-18}
\mottonScoreRow{6}{}\cline{2-18}
\mottonScoreRow{5}{}\cline{2-18}
\mottonScoreRow{4}{}\cline{2-18}
\mottonScoreRow{3}{}\cline{2-18}
\mottonScoreRow{2}{}\cline{2-18}
\mottonScoreRow{1}{}\Cline{2pt}{2-18}
\mottonScoreRow{1}{}\cline{2-18}
\mottonScoreRow{2}{}\cline{2-18}
\mottonScoreRow{3}{}\cline{2-18}
\mottonScoreRow{4}{}\cline{2-18}
\mottonScoreRow{5}{}\cline{2-18}
\mottonScoreRow{6}{}\cline{2-18}
\mottonScoreRow{7}{}\cline{2-18}
\mottonScoreRow{8}{}\cline{2-18}
\mottonScoreRow{9}{}\cline{2-18}
\mottonScoreRow{10}{}\cline{1-18}
\end{tabularx}
}

\multicolumn{1}{|c}{#2} & \multicolumn{1}{|c|}{\textbf{#1}}
}

\newcommand\mottonData{%
\setlength{\extrarowheight}{3pt}
\begin{tabular}{cc|*{11}{c|}}
\cline{3-13}
& & \multicolumn{11}{c|}{\textbf{Levées réalisées}} \\
\cline{3-13}
& & \textbf{0} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} & \textbf{6} & \textbf{7} & \textbf{8} & \textbf{9} & \textbf{10} \\
\cline{1-13}
& 10 & 11 & 14 & 19 & 26 & 35 & 46 & 59 & 74 & 91 & 110 \\
\cline{2-13}
& 10 & 12 & 16 & 22 & 30 & 40 & 52 & 66 & 82 & 100 \\
\cline{2-12}
& 10 & 13 & 18 & 25 & 34 & 45 & 58 & 73 & 90 \\
\cline{2-11}
& 10 & 14 & 20 & 28 & 38 & 50 & 64 & 80 \\
\cline{2-10}
& 10 & 15 & 22 & 31 & 42 & 55 & 70 \\
\cline{2-9}
& 10 & 16 & 24 & 34 & 46 & 60 \\
\cline{2-8}
& 10 & 17 & 26 & 37 & 50 \\
\cline{2-7}
& 10 & 18 & 28 & 40 \\
\cline{2-6}
& 10 & 19 & 30 \\
\cline{2-5}
& 10 & 20 \\
\cline{1-4}
\end{tabular}
\mottonTitle
$score = (10 + lev\acute{e}es\ r\acute{e}alis\acute{e}es - cartes\ en\ main) \times lev\acute{e}es\ r\acute{e}alis\acute{e}es + 10$
}

\newcommand{\mottonTitle}[1][]{%
\begin{tikzpicture}[#1]
\node[text width=9cm,align=center](titre){\Huge Motton};
\node[text width=9cm,align=center] at ([yshift=-1cm]titre.north){Feuille de score};
\end{tikzpicture}
}

\begin{document}
\pagenumbering{gobble}
\mottonData

\mottonScore

\mottonData

\mottonScore
\end{document}


My questions are:

• Why my tikz picture is vertically aligned with the middle of the table? I was expecting it would be aligned from the top
• Why do I need to set the tikz picture width if I want to center it? Can't I just position the picture where I want?

It seems that there are some misunderstandings, so I'll try to add some clarifications. I am happy with what I've got. I just don't understand how I've got it.

From what I've coded, I thought the picture would be aligned on the top of the table. I was planning to move it down later. But it was already located where I wanted. That's the topic of the first question.

For the second question, if I don't set the width of the node, the node is on the left side, aligned to the edge of the table. My guess is because the node takes only the space needed to display the text contained. Am I right?

• Regarding the second question, where exactly do you want to position it? Sep 23, 2017 at 18:56
• @TorbjørnT. I am happy with what I've got. I just don't understand how I've go it. That's frustrating.
– A.D.
Sep 23, 2017 at 21:05
• Didn't see your edit. To answer the last question: Yes. The space needed for the text plus the inner sep of the node on each side, which is 0.333em by default. (Why would it the node take more space?) Sep 23, 2017 at 21:31

To understand what happens, consider this simplified example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
X
\begin{tabular}{c} 1 \\ 2 \\3 \\4 \end{tabular}
\begin{tikzpicture}
\node [align=center] {Motton\\ Foobar};
% the following line draws a frame around the border of the diagram
\draw (current bounding box.north east) rectangle (current bounding box.south west);
\end{tikzpicture}
X
\end{document}


The output is this:

There are a few things to note:

• The default vertical alignment of a tabular is to center it on the baseline.
• The default vertical aligntment of a tikzpicture is to place its bottom on the baseline.
• A tikzpicture is cropped to its contents.
• As far as positioning on the line/page, a tikzpicture is just a box, and in that sense no different from say the letter X, or a tabular, or an \includegraphics.

The first two points is the reason why your title roughly aligned with the center of the tabular.

Regarding the horizontal positioning, the last two points are the reason you need text width=9cm. That setting makes the node wider, but because the text is centered within that 9cm, the text is pushed to the right of the table. For example, if I add text width=5cm to the node in my example above, I get this:

But to push something a bit right on a line, it's perhaps more natural to insert some horizontal space, so you could add e.g. \hspace{3cm} between \end{tabular} and \begin{tikzpicture}.

try

\newcommand{\mottonTitle}[1][]{%
\begin{tikzpicture}[#1,baseline=(current bounding box.north)]% for align to the top is added baseline
\node[text width=9cm,align=center](titre){\Huge Motton      \\
\normalsize  at   \\
Feuille de score};
\end{tikzpicture}
}


and to table (left of image with title) add optional table align [t]:

\begin{tabular}[t]{cc|*{11}{c|}}% added t


do i correctly understood, what you like to obtain?

edit: for aligning table (tabular environment) and image (tikzpicture environment) with title is important that both have the same baseline. with option [t] (top) the table is aligned to their top. similarly with defined baseline of tikzpicture to be at its north side (current bounding box.north) both baseline are in line. if you not define this, the natural baseline for table is middle of table and image is bottom of image.

• Actually, I am happy with what I've got. I just don't understand why how the positionning works. I thought the picture would be located on the top and I will need to lower it. But I was surprised to see it where I wanted it. Nice node grouping. I didn't know I could do that!
– A.D.
Sep 23, 2017 at 21:03
• @A.D., i add short explanation about aligning of tabular environment and tikzpucture. if answer solve your problem, you can vote it and even accept it :-). Sep 23, 2017 at 21:31