Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can one change the font/fontfamily for the text of a tikz node? I can't seem to find it anywhere.

\begin{tikzpicture}[font=\ttfamily]    
\node[text centered, color=white, rotate=-90, shape=rectangle, fill=black,
   font=\huge, inner sep=3pt,minimum height=1cm] at (0,0) {\textbf{Some Text}}
    ...Another node goes here that is "snapped" to the next one along one of its
    sides and not hard coded...
\end{tikzpicture}

I'd like to put some text right next to the first node without having to hard code the distance(as some text may change)

share|improve this question
    
If you would like to change the font in whole tikz block, you can use \ttfamily just after the \begin{}, without []. –  Sigur Jul 12 '12 at 21:27
    
I can't seem to change the font family and font size independently. –  AbstractDissonance Jul 12 '12 at 21:33
1  
Please add a minimal working example that illustrates your problem. That would clear the confusion about the possible cause of the undesired behavior. –  percusse Jul 12 '12 at 21:54
add comment

1 Answer

up vote 3 down vote accepted

TikZ is very well integrated to TeX and you can use the same methods to modify some texts. For example you can use TeX's groups outside the tikzpicture environment or inside. You can use specific options inside a tikzpicture environment or inside a node. The main rule is that the text inside a node used the font defined outside if you don't use a specific option to change the font.

Now to put some text right the main node, you can use label= ... to define a label node or you can use the positioning library or you can use anchor=

\documentclass[11pt]{scrartcl}  
\usepackage[utf8]{inputenc} 
\usepackage{fourier,tikz}
 \usetikzlibrary{positioning}
\begin{document}  
  Font  by default

\begingroup 
\ttfamily\small
\begin{tikzpicture}
\node {Text in he node};
\end{tikzpicture} 

After the \emph{tikzpicture} but inside the group. 
\endgroup

Outside the  \verb+tikzpicture+ and outside the group.

\begin{tikzpicture}
  \node[font=\huge\bfseries] {Text in he node};
\end{tikzpicture}

\begin{tikzpicture}
 \begingroup \bfseries\small
  \node {First node};
   \endgroup  
  \node at (0,-1) {Second node}; 
\end{tikzpicture} 

\begin{tikzpicture}
  \node[draw,label={[align=left]right:right label\\ok}] {Main label};
\end{tikzpicture} 

 \begin{tikzpicture}
  \node[draw] (main){Main label}; 
  \node[right=0pt of main] (sub){Sub label};
\end{tikzpicture} 

 \begin{tikzpicture}
  \node[draw] (main){Main label}; 
  \node[anchor=west] at (main.east){Sub label};
\end{tikzpicture}   
\end{document}       

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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