1

in tikz matrix i'm trying to set row height relatively to the font size, but for that i need to set it as a numeric value instead of names like \normalsize \large... So i use \fontsize, but so far i've only been able to use it through a macro as i need to first, \setlength{\x}{#1} where \x is used like this \fontsize{\x}{\x}. But in \matrix ... how to run \setlength{\x}{#1} before font=\fontsize{...}{...}? my mwe is...

\documentclass[a4paper]{article}

\usepackage[verbose,vmargin=30mm,hmargin=20mm]{geometry}

\usepackage{tikz} \usetikzlibrary{matrix,calc}

\tikzset{ allmatrix/.style = {matrix of nodes, nodes in empty cells,matrix anchor=north, row sep=-\pgflinewidth, column sep=-\pgflinewidth}, texttable/.style 2 args={nodes={anchor=center,outer sep=0pt,inner sep=3pt, text width=#1,text depth=.5ex,text height=#2, font=\fontsize{#2}{#2}}}}

\setlength{\parindent}{0pt}

\begin{document} \begin{tikzpicture}

\matrix at (0,0) [allmatrix,texttable={60mm}{10pt}] (t1) { firt line\ second line\ } \end{tikzpicture} \end{document}

the macro to be able to use \fontsize is (out of tikz) ...

\newlength\x
\newcommand{\setnumfon}[1]{\setlength\x{#1}\fontsize{\x}{\x}\selectfont}

i don't how to run \setlength in a tikz macro before setting font=\fontsize{\x}{\x}

EDIT: normally we set minimum height= and not text height in tikz matrix. That allows automatic row height adjustment, but actually it also has significant text alignment problem across columns. I have once posted something on this issue, and provided my own solution using text height and text depth. This misalignment is not seen at all in tabular environment with all default settings.

  • Intention of your question is unclear. What you like to achieve? – Zarko Feb 28 '22 at 10:36
  • I don't think your code would compile anyway: texttable/.style 2 ags, you meant 2 args? And the question is quite unclear. You seem to need to transform font names in numbers but nowhere it appears in your code, since you send 10pt to your texttable macro. Please be more specific. – SebGlav Feb 28 '22 at 11:15

1 Answers1

1

To long for comment:

  • what you like achieve with your code?
  • font size is defined by option of document class (for article 10, 11, and 12 pt)
  • those size you can (locally) change by commands \Huge, \huge, ... \scriptsize and \tiny
  • If if those commands don't give you what youafter, you can use macro \fontsize{<size>}{<skip>}\selectfont , where skip is usual about 20% bigger than size (it define text line spacing, see what is skip). For example, defsault values in article is \fontsize{10}{12}selectfont`
  • it is not clear, why you need two styles for defining style of a matrix?

Edit: Regarding defining row height to size of used font: this is done automatically. So it is not clear, what is your problem.

Simplified code which works and gives (to my opinion nice result) is:

\documentclass[margin=3mm, varwidth]{standalone}

\setlength{\parindent}{0pt} \usepackage{tikz} \usetikzlibrary{matrix} \tikzset{ M/.style args = {#1/#2/#3}{% M as Matrix matrix of nodes, nodes in empty cells, nodes = {draw, anchor=center, outer sep=0pt, inner sep=3pt, text width=#1, text depth=0.25ex, font=\fontsize{#2}{#3}\selectfont, row sep=-\pgflinewidth, column sep=-\pgflinewidth}, matrix anchor=north, } } \begin{document} \begin{tikzpicture}
\matrix at (0,0) [M=22mm/10/12] (t1) { first line\ second q line\ }; \end{tikzpicture} \end{document}

enter image description here

If you not like drawn nodes border, delete option draw from nodes options.

If for some reason you persist to hye two styles for defining your matrix style, than you can try, if the following suggestion work for you:

\documentclass[margin=3mm, varwidth]{standalone}

\setlength{\parindent}{0pt} \usepackage{tikz} \usetikzlibrary{matrix} \tikzset{ M/.style = {% M as Matrix matrix of nodes, nodes in empty cells, row sep=-\pgflinewidth, column sep=-\pgflinewidth, matrix anchor=north, }, Mn/.style args = {#1/#2/#3}{% Mn as Matrix nodes nodes = {anchor=center, outer sep=0pt, inner sep=3pt, text width=#1, text depth=0.25ex, font=\fontsize{#2}{#3}\selectfont} } } \begin{document} \begin{tikzpicture}
\matrix at (0,0) [M, Mn=22mm/10/12] (t1) { first line\ second q line\ }; \end{tikzpicture} \end{document}

In the both cases the compilation result is the same!

\documentclass[margin=3mm, varwidth]{standalone}

\setlength{\parindent}{0pt} \usepackage{tikz} \usetikzlibrary{matrix} \tikzset{ M/.style = {% M as Matrix matrix of nodes, nodes in empty cells, row sep=-\pgflinewidth, column sep=-\pgflinewidth, matrix anchor=north, }, Mn/.style args = {#1/#2/#3}{% Mn as Matrix nodes nodes = {anchor=center, outer sep=0pt, inner sep=3pt, text width=#1, text height=#3, text depth=0.25ex, font=\fontsize{#2}{#3}\selectfont} } }

However, if you will

Zarko
  • 296,517
  • As i clearly mentioned in my post initially, i.e. even before editing it, I'd like to set "text height" (awkwardly i have written row height) relatively to the font size. And the code shows it well; text height=#2 ... font=\fontsize{#2}{#2} If that works I will add factors to make it look correct. – user1850133 Feb 28 '22 at 11:52