3

I have used the \multiput command to create a for example 4 by 4 table:

\documentclass[a4paper,12pt]{report}‎
‎\usepackage{graphicx} % inserting images‎‎

‎\begin{document}‎‎‎‎
‎‎
\setlength{\unitlength}{2mm}
\begin{picture}(4,4)‎
\multiput(25,0)(5,0){5}%
{\line(0,1){20}}
\multiput(25,0)(0,5){5}%
{\line(1,0){20}}
\end{picture}‎‎‎
‎
‎\end{document}‎

how can I put text into each small square?

user3482383
  • 1,629

2 Answers2

3

If you are really doing a picture (although your example sure looks like a table), then probably is best done to use a modern drawing package such astikz:

enter image description here

Code:

\documentclass{report}
\usepackage{tikz}

\newcommand{\NodeWidth}{1.0cm}% \newcommand{\NodeHeight}{1.0cm}% \tikzset{My Node Style/.style={rectangle, ultra thick, minimum width=\NodeWidth, minimum height=\NodeHeight}} \newcommand{\FourNodes}[6][draw=black]{% \node [My Node Style, #1] at (0,#2\NodeHeight) {#3\strut}; \node [My Node Style, #1] at (\NodeWidth,#2\NodeHeight) {#4\strut}; \node [My Node Style, #1] at (2\NodeWidth,#2\NodeHeight) {#5\strut}; \node [My Node Style, #1] at (3\NodeWidth,#2*\NodeHeight) {#6\strut}; }%

\begin{document}‎‎‎‎ \begin{tikzpicture} \FourNodes{0.0cm}{a}{b}{c}{d} \FourNodes{-1}{x}{y}{z}{w} \FourNodes{-2}{1}{2}{3}{4} \FourNodes{-3}{r}{g}{t}{u} \end{tikzpicture} \end{document}‎

Peter Grill
  • 223,288
0

This one uses matrix

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\tikzset{
table/.style={
  matrix of nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={rectangle,minimum size = 1cm,align=center,inner sep=0pt},
  text depth=1.25ex,
  text height=2.5ex,
  nodes in empty cells
},
}

\begin{document}

\begin{tikzpicture}
% the matrix entries
\matrix (mat) [table]
{
 a & b & c & d \\
 x & y & z & w \\
 1 & 2 & 3 & 4 \\
 r & g & t & u \\
};
\foreach \x in {1,...,4}
{
  \draw[ultra thick]
    ([xshift=-.5\pgflinewidth]mat-\x-1.south west) --
    ([xshift=.5\pgflinewidth]mat-\x-4.south east);
  }
  \draw[ultra thick]
    ([xshift=-.5\pgflinewidth]mat-1-1.north west) --
    ([xshift=-.5\pgflinewidth]mat-1-4.north east);
\foreach \x in {1,...,4}
{
  \draw[ultra thick]
    ([yshift=.5\pgflinewidth]mat-1-\x.north east) --
    ([yshift=.5\pgflinewidth]mat-4-\x.south east);
}
\draw[ultra thick]
      ([yshift=.5\pgflinewidth]mat-1-1.north west) --
      ([yshift=.5\pgflinewidth]mat-4-1.south west);

\end{tikzpicture}

\end{document}

enter image description here

Easier version in which

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\tikzset{
table/.style={
  matrix of nodes,
  row sep=-4\pgflinewidth,    %% adjust
  column sep=-4\pgflinewidth,  %% adjust
  nodes={draw, ultra thick,rectangle,minimum size = 1cm,align=center,inner sep=0pt},
  text depth=1.25ex,
  text height=2.5ex,
  nodes in empty cells
},
}

\begin{document}

\begin{tikzpicture}
% the matrix entries
\matrix (mat) [table]
{
 a & b & c & d \\
 x & y & z & w \\
 1 & 2 & 3 & 4 \\
 r & g & t & u \\
};
\end{tikzpicture}

\end{document}