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?

  • The tabular environment may be what you are looking for. Consult any elementary text on LaTeX. – Steven B. Segletes Oct 23 '14 at 19:40
  • Actually it is a figure, for some part of it I want to add some text to each small square – user3482383 Oct 23 '14 at 19:42
  • @AndrewCashner I have edited it – user3482383 Oct 23 '14 at 19:47
  • For laying text onto an image (maybe what you meant by "figure"), there are various approaches, including this one: tex.stackexchange.com/questions/171483/… – Steven B. Segletes Oct 23 '14 at 19:58
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}‎
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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.