3

So i wanted to create a table with fixed width & height filling the whole page (10cm x 10cm) and decided to use tikz (i have absolutely no experience in latex so i thought an svg-like solution would be simpler for me). The code looks like this:

\documentclass{article}

\usepackage[paperheight=10cm, paperwidth=10cm, left=-5.47mm, right=0mm, top=0mm, bottom=0mm]{geometry}
\usepackage{tikz}
\usepackage{calc}

\begin{document}
\newcommand{\drawlines}{
    \foreach \y in {1,...,11} 
    {
        \draw[thick] (0, \y * 10 / 11.04) -- (10, \y * 10 / 11.04);
    }
}

\begin{tikzpicture}[scale=1]
    %Horizontal line  nr1
    \draw[thick] (0, 0.011) -- (10, 0.011);
    
    %Horizontal lines nr2-nr12
    \drawlines

    %Vertical lines
    \draw[thick] (0.020, 0) -- (0.020, 9.97);
    \draw[thick] (2.500, 0) -- (2.500, 9.97);
    \draw[thick] (5.000, 0) -- (5.000, 9.97);
    \draw[thick] (7.500, 0) -- (7.500, 9.97);
    \draw[thick] (9.984, 0) -- (9.984, 9.97);

    %Text
    
\end{tikzpicture}
\end{document}

And the result is this

The result

Each cell should contain either an image or a text (all of them have fixed lengths/sizes)

3
  • 2
    If you would like to stay in the TikZ-ecosystem, maybe a tikz matrix would be more convenient than manually drawing all the lines: tikz.dev/tikz-matrices Commented Aug 13 at 15:13
  • welcome! what is left=-5.47mm supposed to achieve?
    – cfr
    Commented Aug 13 at 15:52
  • the -5.47mm is to get rid of the margin, else idk how to get rid of this, i literally started yesterday with latex lol
    – end41r
    Commented Aug 13 at 19:51

1 Answer 1

3

Here's a simple approach which doesn't use a matrix (but might be simpler if it did?).

The basic idea is to set x and y to one eighth and one eighteenth of the width or height of the paper, after deducting 0.8pt to account for twice half the width of the lines.

Loops are used to create coordinates named c-x0 through c-x8 and c-y0 through c-y8, as well as to draw the lines. I could not get the dimensions to quite agree - probably because of some space I've forgotten to remove - so I drew the lines using overlay to avoid altering the bounding box with current page node anchors for reference points.

The final lines demonstrate how to add text and graphics using the framework of named coordinates previously created. Basically, odd numbers are where you want to put things. Even numbers are for lines.

grid with random bits of text and sample images in various boxes

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/724361/
\usepackage[paperheight=10cm, paperwidth=10cm, margin=0mm, scale=1]{geometry}
\usepackage{tikz}
\usepackage{calc}
\parindent=0pt
\newlength\modwd
\newlength\modht
\AddToHook{begindocument}{%
\setlength\modwd{\dimexpr\paperwidth-0.8pt}%
\setlength\modht{\dimexpr\paperheight-0.8pt}%
}
\begin{document}
\begin{tikzpicture}[x=\modwd/8,y=\modht/18]
\foreach \c in {0,...,8} \coordinate (c-x\c) at (\c,0);
\foreach \c in {0,...,18} \coordinate (c-y\c) at (0,\c);
\begin{scope}[overlay]
\foreach \i in {0,2,4,6,8}
{
\draw [thick] (current page.north -| c-x\i) -- (current page.south -| c-x\i);
}
\foreach \i in {0,2,...,18}
{
\draw [thick] (current page.west |- c-y\i) -- (current page.east |- c-y\i);
}
\end{scope}
\path (current page.north east) (current page.south west);
\foreach \i/\j/\k in {1/1/A,3/5/ABC,7/1/aardvark,3/15/bonobo} \node at (c-x\i |- c-y\j) {\k};
\foreach \i/\j/\k in {1/11/example-image-a,3/9/cow,5/7/mill} \node at (c-x\i |- c-y\j) {\includegraphics[width=2cm,height=7.5mm,keepaspectratio]{\k}};
\end{tikzpicture}
\end{document}

If anybody knows how to copy text from Konsole without looking indentation, please let me know!

1
  • WOW, this is a crazy approach, tysm for the solution!!
    – end41r
    Commented Aug 13 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .