3

I would like to draw in LaTeX

  • rectangles regularly spaced,
  • 4 lines of rectangles,
  • each line containing 2 rectangles

in which I am allowed to type texts and equations. Any LaTeX code for that?

EDIT Specifically I would like to reproduce the following picture

enter image description here

Ruben
  • 13,448
  • Welcome to TeX.SX! What is a "line of rectangles"? And how can a line contain rectangles? For the first one you can search any TikZ guide. It's a basic feature. – Ruben Apr 11 '16 at 16:16
  • Regarding your edit: So you are looking for an array which cells are partially framed. That can easily be done with a tabular. I'll add an answer. – Ruben Apr 11 '16 at 18:39

3 Answers3

4

The straightforward way can be this (obviously, you will define macros for the boxes, but this is to give an idea), using basic LaTeX boxes:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
\parindent=0pt\relax % no indent at the start of the paragraph
\fbox{\parbox[t][3cm][c]{5cm}{
    Some text
}}\hspace{0.5cm} %% this is the horizontal separation
\fbox{\parbox[t][3cm][c]{5cm}{
    Some text

    \[ f(x) = formula \]
}} 

\vspace{0.5cm} % and this the vertical one --- notice you star a paragraph here (blank lines)

\fbox{\parbox[t][3cm][c]{5cm}{
    Some text
}}\hspace{0.5cm}  
\fbox{\parbox[t][3cm][c]{5cm}{
    Some text
}} 

%% repeat as needed

\end{document}

which results in

output of above code

Or ...

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\parindent=0pt\relax
\newcommand{\mybox}[1]{\fbox{\parbox[c][2cm][c]{3cm}{#1}}}

\begin{document}

Text \mybox{some text} \quad \mybox{$f(x)$} more text

\bigskip
Text \mybox{some text} \quad \mybox{yeap} and more text

\bigskip
To align it \mybox{you have} \quad \mybox{to use} a tabular or similar...

\end{document}

Which gives:

New output

Obviously, you can use the package tcolorbox for a MUCH better look... just read the manual and try!

Example from tcolorbox package

Rmano
  • 40,848
  • 3
  • 64
  • 125
3

You may want to try the matrix approach from TiKZ. This is just an example, but many positioning and style aspects may be added.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{squarestyle/.style={draw,text width=2cm,text height=1cm}}
\tikzset{matrixstyle/.style={matrix of nodes,nodes in empty cells,ampersand replacement=\&,column sep=2em,row sep=2ex}}

\begin{document}

\begin{tikzpicture}
    \matrix (m) [%
        matrixstyle,
        column 2/.style={nodes={squarestyle}},
        column 3/.style={nodes={squarestyle}},
    ]
    {%
        Something \& A \& B \& Text \\
        Something \& A \& B \& Text \\
    };
\end{tikzpicture}

\end{document}

enter image description here

cacamailg
  • 8,405
3
\documentclass{article}
\usepackage{collcell}
  \newcolumntype{f}{>{\collectcell\cellframe}l<{\endcollectcell}}
  \newcommand*\cellframe[1]{\fbox{\makebox[2em][l]{\strut#1}}}

\begin{document}
\begin{tabular}{lffl}
  something & x &    & text \\[10pt]
  something &   &    & text \\[10pt]
  something &   & xy & text \\[10pt]
  something &   &    & text
\end{tabular}
\end{document}

output_crop

Note. Of course, you can use math mode in every cell of this tabular.

Ruben
  • 13,448