Graphics, Figures & TablesHow to change tikZ matrix height

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

How to change tikZ matrix height

Post by dmuthu_cse »

Hello friends,

I have drawn a table using tikz, according to your advice. But now i need to increase the size of the columns and rows. But after increasing the size, the lines are not exactly cutting the table elements as they have gone down.

Please do help, i am enclosing the code,

Code: Select all

\begin{center}
\small
      \begin{tikzpicture}

    \matrix (magic) [%
      matrix of nodes,
      text width=6.5mm,
		text height=3mm,
      text badly centered
    ]
{%
0 & 6 & 11\\
0 & 3 & 4\\
0 & 0 & 0\\
    };
    % striking out lines
    \draw[thin,black] (magic-1-1.north) -- (magic-3-1.south);
    \draw[thin,black] (magic-3-1.west) -- (magic-3-3.east);
    % horizontal lines of the table
    \foreach \i in {1,2,3}
      \draw[thin,black] (magic-\i-1.north west) -- (magic-\i-3.north east);
    \draw[thin,black] (magic-3-1.south west) -- (magic-3-3.south east);
    % vertical lines of the table
    \foreach \j in {1,2,3}
      \draw[thin,black] (magic-1-\j.north west) -- (magic-3-\j.south west);
    \draw[thin,black] (magic-1-3.north east) -- (magic-3-3.south east);
  \end{tikzpicture}
\end{center}
Note: the horizontal cutting line, is not going through 0 0 0 as the vertical line goes perfectly.

Thanks in advance,

Regards,
Muthu.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

How to change tikZ matrix height

Post by localghost »

dmuthu_cse wrote:[...] I have drawn a table using tikz, according to your advice. [...]
But you didn't formulate your question according to our advice [1]. Regarding your problem the pgf/tikZ manual tells you the details (keyword »matrix library«).

[1] View topic: Avoidable mistakes


Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

How to change tikZ matrix height

Post by dmuthu_cse »

Hello thorsten,

Very sorry for the previous confusing post. I have gone through the manual but still i didnt get the key point.

Now i have elobrated my problem with two tables the first table is facing problem, while the second one is correct but the cell width and height to be increased.

In first table the table elements are aligned bottom, but it should be aligned center. Please help me in this regard. I am herewith attaching the code.

Code: Select all

\documentclass[b5paper,11pt]{book}
\usepackage{fancybox,array,amsmath,ulem}
\usepackage{tikz-inet,pgf}
\usetikzlibrary{matrix}
\begin{document}
\begin{center}
\small
      \begin{tikzpicture}

    \matrix (magic) [%
      matrix of nodes,
      text width=6.5mm,
		text height=3mm,
      text badly centered
    ]
{% 

\sout{0.5} & \sout{0} & \sout{0} & \sout{0} & \sout{0} & \sout{0}\\
\sout{0} & \sout{0} & \sout{0.5} & \sout{1} & \sout{2.0} & \sout{0}\\
1.0 & 1.5 & 1.0 & 3 & 3.5 & \sout{0}\\
1.5 & 2.0 & 1.0 & 3 & 3.5 & \sout{0}\\
2.0 & 2.0 & 2.0 & 3 & 5.0 & \sout{0}\\
4.0 & 4.0 & 4.0 & 4 & 5.0 & \sout{0}\\
    };
    % striking out lines
\draw[thin,black] (magic-1-6.north) -- (magic-6-6.south);
    \draw[thin,black] (magic-1-1.west) -- (magic-1-6.east);
    \draw[thin,black] (magic-2-1.west) -- (magic-2-6.east);
    % horizontal lines of the table
    \foreach \i in {1,2,3,4,5,6}
      \draw[thin,black] (magic-\i-1.north west) -- (magic-\i-6.north east);
    \draw[thin,black] (magic-6-1.south west) -- (magic-6-6.south east);
    % vertical lines of the table
    \foreach \j in {1,2,3,4,5,6}
      \draw[thin,black] (magic-1-\j.north west) -- (magic-6-\j.south west);
    \draw[thin,black] (magic-1-6.north east) -- (magic-6-6.south east);
  \end{tikzpicture}
\end{center}
% this is correct but the cell width and height should be increased
\begin{center}
\small
      \begin{tikzpicture}

    \matrix (magic) [%
      matrix of nodes,
      text width=4.5mm,
      text badly centered
    ]
{% 

\sout{0.5} & \sout{0} & \sout{0} & \sout{0} & \sout{0} & \sout{0}\\
\sout{0} & \sout{0} & \sout{0.5} & \sout{1} & \sout{2.0} & \sout{0}\\
1.0 & 1.5 & 1.0 & 3 & 3.5 & \sout{0}\\
1.5 & 2.0 & 1.0 & 3 & 3.5 & \sout{0}\\
2.0 & 2.0 & 2.0 & 3 & 5.0 & \sout{0}\\
4.0 & 4.0 & 4.0 & 4 & 5.0 & \sout{0}\\
    };
    % striking out lines
\draw[thin,black] (magic-1-6.north) -- (magic-6-6.south);
    \draw[thin,black] (magic-1-1.west) -- (magic-1-6.east);
    \draw[thin,black] (magic-2-1.west) -- (magic-2-6.east);
    % horizontal lines of the table
    \foreach \i in {1,2,3,4,5,6}
      \draw[thin,black] (magic-\i-1.north west) -- (magic-\i-6.north east);
    \draw[thin,black] (magic-6-1.south west) -- (magic-6-6.south east);
    % vertical lines of the table
    \foreach \j in {1,2,3,4,5,6}
      \draw[thin,black] (magic-1-\j.north west) -- (magic-6-\j.south west);
    \draw[thin,black] (magic-1-6.north east) -- (magic-6-6.south east);
  \end{tikzpicture}
\end{center}
\end{document}
Attachments
k.pdf
(6.78 KiB) Downloaded 388 times
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to change tikZ matrix height

Post by gmedina »

Hi,

one possible solution is to use the text depth=<length> option to compensate the effect of text height; an example:

Code: Select all

\documentclass[b5paper,11pt]{book}
\usepackage{fancybox,array,amsmath,ulem}
\usepackage{tikz-inet,pgf}
\usetikzlibrary{matrix}
\begin{document}

% this is correct but the cell width and height should be increased
\begin{center}
\small
      \begin{tikzpicture}

    \matrix (magic) [%
      matrix of nodes,
      text width=7mm,
      text height=6mm,
      text depth=8mm,
      text badly centered
    ]
{% 

\sout{0.5} & \sout{0} & \sout{0} & \sout{0} & \sout{0} & \sout{0}\\
\sout{0} & \sout{0} & \sout{0.5} & \sout{1} & \sout{2.0} & \sout{0}\\
1.0 & 1.5 & 1.0 & 3 & 3.5 & \sout{0}\\
1.5 & 2.0 & 1.0 & 3 & 3.5 & \sout{0}\\
2.0 & 2.0 & 2.0 & 3 & 5.0 & \sout{0}\\
4.0 & 4.0 & 4.0 & 4 & 5.0 & \sout{0}\\
    };
    % striking out lines
\draw[thin,black] (magic-1-6.north) -- (magic-6-6.south);
    \draw[thin,black] (magic-1-1.west) -- (magic-1-6.east);
    \draw[thin,black] (magic-2-1.west) -- (magic-2-6.east);
    % horizontal lines of the table
    \foreach \i in {1,2,3,4,5,6}
      \draw[thin,black] (magic-\i-1.north west) -- (magic-\i-6.north east);
    \draw[thin,black] (magic-6-1.south west) -- (magic-6-6.south east);
    % vertical lines of the table
    \foreach \j in {1,2,3,4,5,6}
      \draw[thin,black] (magic-1-\j.north west) -- (magic-6-\j.south west);
    \draw[thin,black] (magic-1-6.north east) -- (magic-6-6.south east);
  \end{tikzpicture}
\end{center}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

Re: How to change tikZ matrix height

Post by dmuthu_cse »

Hello gmedina,

Thanks for your response. I am happy now, now the table is looking good.

Thanks again for saving me.

Regards,
Muthu
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

How to change tikZ matrix height

Post by dmuthu_cse »

Hello friends,

I am back with tikz, but now it is not at all executing saying errors while compiling.

My error is:
TeX capacity exceeded, sorry [grouping levels=255].

My code is

Code: Select all

\documentclass[b5paper,10.5pt]{book}
\usepackage{fancybox,array,amsmath,ulem,amssymb}
\usepackage{tikz-inet,pgf}
\usetikzlibrary{matrix,calc}
\usepackage[centering,
  headheight=14pt,
  headsep=10pt,
  includehead,
  papersize={18cm,24cm},
  text={15.25cm,19.2cm},
  dvips=false,
  pdftex=false,
  vtex=false
]{geometry}
\usepackage{graphicx,colortbl}
\usepackage{threeparttable,booktabs,multirow}

\usepackage{tikz-inet}
\usetikzlibrary{matrix}
% nodes with circle
\newcommand{\mymk}[1]{%
  \tikz \node[anchor=south west, draw,circle, inner sep=0pt, minimum size=7mm,
    text height=2mm]{\ensuremath{#1}} ;}
% nodes without border
\newcommand{\none}[1]{%
  \tikz \node[anchor=south west, rectangle, inner sep=0pt, minimum size=7mm,
    text height=2mm]{\ensuremath{#1}} ;}

\newcommand\ventry{\multicolumn{1}{c}{}}

\begin{center}
\small
      \begin{tikzpicture}

    \matrix (magic) [%
      matrix of nodes,
   text width=7mm,
      text height=2.8mm,
      text depth=4mm,
      text badly centered
    ]
{% 
 & W1 & W2 & W3 & W4 & Supply\\
 & 6(6) & 4 & 1 & 5 & 14\\
 & 8 & 9 & 2 & 7 & 16\\
 & 4 & 3 & 2 & 6 & 05\\
Demand & 06 & 10 & 15 & 04 & 35\\
 & \mymk{1} &  &  &  &  \\
    };
    % striking out lines
\draw[thin,black] (magic-1-2.north) -- (magic-6-2.south);

    % horizontal lines of the table
    \foreach \i in {1,2,3,4,5,6}
      \draw[thin,black] (magic-\i-1.north west) -- (magic-\i-6.north east);
    \draw[thin,black] (magic-6-1.south west) -- (magic-6-6.south east);
    % vertical lines of the table
    \foreach \j in {1,2,3,4,5,6}
      \draw[thin,black] (magic-1-\j.north west) -- (magic-6-\j.south west);
    \draw[thin,black] (magic-1-6.north east) -- (magic-6-6.south east);
  \end{tikzpicture}
\end{center}

\end{document}
           
                                           
Regards,
Muthu
Post Reply