5

I am developing a figure in (k)tikz. Here's the code:

\begin{tikzpicture}[every node/.style={draw,rounded corners, minimum height=18, right}]

\node[text width=3.5cm] at (-3,-3) {
 $\quad\, d(start_1 - end_0 - 1)$ \\ 
 $=d(1-0-1)$ \\
 $=d(0)$
};
\end{tikzpicture}

text width=3.5cm is used as a hack, since \\, doesn't seem to have any effect. (Update: percusse has an answer for that)

In ktikz(left) it looks just fine, but when I include it in my latex document via "\input{file}", the node gets narrower and the text is broken too early.

This is very annoying, because the real time preview of ktikz makes the development comfortable, but I want to know how it will look in latex of course.

Progress:

Paul Gessler first pointed out that the fonts are different. So I tried to determine the font used in my document, planning to set it in ktikz.

So I included \encodingdefault, \familydefault, \seriesdefault and \shapedefault in the latex document and pasted the values as \usefont{T1}{aer}{m}{n} in the ktikz preamble. This did change the normal font (yet an extra non-math line abcd..tuv still takes more space in the latex document) but not the math font.

Today, I found my error! \usepackage{mathptmx} in the ktikz template caused the different font. Commenting it out solved the issue.

  • You need to use the same font in both places. It looks like kTikZ is using some Times clone, which is quite a bit narrower than Computer Modern. – Paul Gessler Aug 7 '14 at 11:24
  • 2
    By the way: using text width is not a hack. Line breaks by design don't work in node texts unless text width and/or align are set. – Paul Gessler Aug 7 '14 at 11:26
6

The regular TikZ node has \hbox as the content container. When you use align=<center,left,right....> or text <property>=<dimension> TikZ starts using minipage environment for the contents.

That means you can use mathematical display style environments such as below and adjust with enough space declaration. If you want to use the same text in both places you can click the edit button and adjust your template such that it uses the font that you use in your master document.

\begin{tikzpicture}[every node/.style={draw,rounded corners}]

\node[text width=3.5cm] at (0,0) {% We are in a minipage now
\setlength{\abovedisplayskip}{0pt}% Remove the top vertical skip
\begin{align*} &d(start_1 - end_0 - 1) \\ 
 ={}&d(1-0-1) \\
 ={}&d(0)
\end{align*}};
\end{tikzpicture}

enter image description here

|improve this answer|||||
  • Thanks for the minipage tip! Adjusting the template did the job. – user2740 Aug 22 '14 at 21:03

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.