pele_mele:stack_exchange:tex_latex:392900
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
pele_mele:stack_exchange:tex_latex:392900 [2024/11/23 04:02] – supprimée - modification externe (Date inconnue) 127.0.0.1 | pele_mele:stack_exchange:tex_latex:392900 [2024/11/23 04:02] (Version actuelle) – ↷ Nom de la page changé de pele_mele:stack_exchange:tex_latex:tex-392900 à pele_mele:stack_exchange:tex_latex:392900 alexis | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== How positioning works with tikz ====== | ||
+ | I am back again with [[https:// | ||
+ | |||
+ | 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: | ||
+ | |||
+ | <code latex> | ||
+ | \documentclass{letter} | ||
+ | |||
+ | \usepackage[a4paper, | ||
+ | \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}{# | ||
+ | \noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}} | ||
+ | |||
+ | \newcommand\VRule{\vrule width 2pt} | ||
+ | |||
+ | \newcommand\mottonScoreHeader[2]{% | ||
+ | \multicolumn{1}{|c}{\textbf{# | ||
+ | \multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{# | ||
+ | } | ||
+ | |||
+ | \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]{% | ||
+ | \mottonScoreHeader{# | ||
+ | } | ||
+ | |||
+ | \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} | ||
+ | } | ||
+ | |||
+ | \newcommand\mottonDataHeader[2]{% | ||
+ | \multicolumn{1}{|c}{# | ||
+ | } | ||
+ | |||
+ | \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} | ||
+ | \mottonDataHeader{10}{\multirow{10}{*}{\rotatebox[origin=c]{90}{\textbf{Cartes en main}}}} | ||
+ | & 10 & 11 & 14 & 19 & 26 & 35 & 46 & 59 & 74 & 91 & 110 \\ | ||
+ | \cline{2-13} | ||
+ | \mottonDataHeader{9}{} | ||
+ | & 10 & 12 & 16 & 22 & 30 & 40 & 52 & 66 & 82 & 100 \\ | ||
+ | \cline{2-12} | ||
+ | \mottonDataHeader{8}{} | ||
+ | & 10 & 13 & 18 & 25 & 34 & 45 & 58 & 73 & 90 \\ | ||
+ | \cline{2-11} | ||
+ | \mottonDataHeader{7}{} | ||
+ | & 10 & 14 & 20 & 28 & 38 & 50 & 64 & 80 \\ | ||
+ | \cline{2-10} | ||
+ | \mottonDataHeader{6}{} | ||
+ | & 10 & 15 & 22 & 31 & 42 & 55 & 70 \\ | ||
+ | \cline{2-9} | ||
+ | \mottonDataHeader{5}{} | ||
+ | & 10 & 16 & 24 & 34 & 46 & 60 \\ | ||
+ | \cline{2-8} | ||
+ | \mottonDataHeader{4}{} | ||
+ | & 10 & 17 & 26 & 37 & 50 \\ | ||
+ | \cline{2-7} | ||
+ | \mottonDataHeader{3}{} | ||
+ | & 10 & 18 & 28 & 40 \\ | ||
+ | \cline{2-6} | ||
+ | \mottonDataHeader{2}{} | ||
+ | & 10 & 19 & 30 \\ | ||
+ | \cline{2-5} | ||
+ | \mottonDataHeader{1}{} | ||
+ | & 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}[# | ||
+ | \node[text width=9cm, | ||
+ | \node[text width=9cm, | ||
+ | \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, | ||
+ | |||
+ | 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? | ||
+ | |||
+ | <WRAP help> | ||
+ | To understand what happens, consider this simplified example: | ||
+ | |||
+ | <code latex> | ||
+ | \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 '' | ||
+ | * The default vertical aligntment of a '' | ||
+ | * A '' | ||
+ | * As far as positioning on the line/page, a '' | ||
+ | |||
+ | The first two points is the reason why your title roughly aligned with the center of the tabular. | ||
+ | |||
+ | Regarding the horizontal positioning, | ||
+ | |||
+ | {{: | ||
+ | |||
+ | 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. '' | ||
+ | </ | ||
+ | <WRAP help> | ||
+ | try | ||
+ | |||
+ | <code latex> | ||
+ | \newcommand{\mottonTitle}[1][]{% | ||
+ | \begin{tikzpicture}[# | ||
+ | \node[text width=9cm, | ||
+ | \normalsize | ||
+ | Feuille de score}; | ||
+ | \end{tikzpicture} | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | and to table (left of image with title) add optional table align '' | ||
+ | |||
+ | <code latex> | ||
+ | \begin{tabular}[t]{cc|*{11}{c|}}% added `t` | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | do i correctly understood, what you like to obtain? | ||
+ | |||
+ | **edit:** for aligning table ('' | ||
+ | </ | ||
+ | <WRAP info> | ||
+ | [[https:// | ||
+ | </ | ||