1

I have two problems with this drawing:

  1. The drawing is not centered, as you can see in the image below (see the red lines).
  2. In order to place $\lambda_\mathrm{acc}$ in the position where it is (see the image), I expected its coordinates to be roughly at (0.5,0.5); instead, why is it located at (2,0.5)?

    \documentclass[11pt,a4paper]{article}
    \usepackage[T1]{fontenc}                
    \usepackage[utf8]{inputenc}             
    \usepackage[english,italian]{babel}
    \usepackage{graphicx}
    \usepackage{caption}                    
    \usepackage{amsmath,amssymb,amsthm}
    \usepackage{tikz}
        \usetikzlibrary{shapes.arrows}
    \usepackage[%bindingoffset=1.5cm, 
    left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}
    
    \begin{document}
    
    \title{Title}
    \author{Author} 
    \date{22 dicembre 2015}
    
    \maketitle
    
    \begin{figure}
      \centering
        \begin{tikzpicture}
        \draw [help lines] (0,0) grid (10,10);
        \draw [] (0,0) rectangle (6,1); %acciaio
        \draw [] (0,4.5) rectangle (6,5.5); %piastra impingement
        \node [text width=3cm,font=\footnotesize] at (2,0.5) {$\lambda_\mathrm{acc}$};
        \node [text width=3cm,font=\footnotesize] at (7.6,5) {piastra\\impingement};
        \draw [latex-latex]  (-0.2,0) -- (-0.2,1) node [black,midway,xshift=-0.4cm]{s\ped{acc}};;
        \end{tikzpicture}
        \caption{Distribuzione puntuale di Nusselt per $Re=5000$}\label{fig:Nu_Re5000}
    \end{figure}
    \end{document}
    

Complete drawing

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}             
\usepackage[english,italian]{babel}
\usepackage{graphicx}
\usepackage{caption}                    
\usepackage{amsmath,amssymb,amsthm}
\usepackage{xcolor}
    \colorlet{ColorPink}{red!10}
\usepackage{tikz}
    \usetikzlibrary{shapes.arrows}
    \usetikzlibrary{decorations.pathreplacing} %curly bracket
\usepackage[%bindingoffset=1.5cm, 
left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}

\begin{document}

\title{Title}
\author{Author} 
\date{22 dicembre 2015}

\maketitle

\begin{figure}
  \centering
    \begin{tikzpicture}
    \draw [help lines] (0,0) grid (10,10);
    \draw [fill=blue!30] (0,0) rectangle (6,1); %acciaio
    \draw [fill=blue!15] (0,1) rectangle (6,1.8); %biadesivo
    \draw [fill=gray!10] (0,1.8) rectangle (6,2.3); %inconel
    \draw [fill=blue!30] (0,4.5) rectangle (6,5.5); %piastra impingement
    \draw [fill=white]   (2.4,4.5) rectangle (3.6,5.5); %hole
    \draw [fill=blue!30] (2.75,-0.4) rectangle (3.15,-0.5); %lens
    \draw [fill=blue!30] (2.55,-0.5) rectangle (3.35,-1.5); %camera
    \node [text width=3cm,font=\footnotesize] at (7.6,5) {piastra\\impingement};
    \node [text width=3cm,font=\footnotesize] at (6,0.5) {acciaio};
    \node [text width=3cm,font=\footnotesize] at (6,1.4) {biadesivo};
    \node [text width=3cm,font=\footnotesize] at (6,2.05) {inconel};
    \node [text width=3cm,font=\footnotesize] at (2,2.05) {$\lambda_\mathrm{inc}$};
    \node [text width=3cm,font=\footnotesize] at (2,1.4) {$\lambda_\mathrm{biad}$};
    \node [text width=3cm,font=\footnotesize] at (2,0.5) {$\lambda_\mathrm{acc}$};
    \node [text width=3cm,font=\footnotesize] at (5,-1) {IR camera};
    \node [text width=3cm,font=\small] at (6.8,-1) {$\varepsilon_\mathrm{amb}$};
    \node [text width=3cm,font=\small] at (6.5,-0.4) {$\varepsilon_\mathrm{ext}$};
    \node [text width=3cm,font=\footnotesize] at (8.1,1.2) {piastra\\target};
    \node [text width=3cm,font=\footnotesize] at (5.4,4.2) {getto};
    \node [text width=3cm,font=\small] at (6.5,2.5) {$\varepsilon_\mathrm{int}$};
    \node [text width=3cm,font=\small] at (6.5,4.2) {$\varepsilon_\mathrm{acc}$};
    \node [text width=3cm,font=\small] at (2.6,2.6) {$\dot{q}_\mathrm{joule}$};
    \draw [-latex,ultra thick]  (1,2.3) -- +(1.1,0);
    \node[single arrow,draw=black,fill=blue,minimum height=1cm,minimum width=1cm,shape border rotate=270] at (3,4.5) {}; %freccia blu
    \draw [decorate,decoration={brace,amplitude=10pt,mirror,raise=1pt},yshift=10pt] %parentesi graffa
    (6.1,-0.3) -- (6.1,1.95) node [black,midway,xshift=0.8cm]{};
    \draw [] (0,0) -- (-0.4,0);
    \draw [] (0,1) -- (-0.4,1);
    \draw [] (0,1.8) -- (-0.4,1.8);
    \draw [] (0,2.3) -- (-0.4,2.3);
    \draw [latex-latex]  (-0.2,0) -- (-0.2,1) node [black,midway,xshift=-0.4cm]{s\ped{acc}};;
    \draw [latex-latex]  (-0.2,1) -- (-0.2,1.8) node [black,midway,xshift=-0.4cm]{s\ped{biad}};;
    \draw [latex-latex]  (-0.2,1.8) -- (-0.2,2.3) node [black,midway,xshift=-0.4cm]{s\ped{inc}};;
    \end{tikzpicture}
    \caption{Distribuzione puntuale di Nusselt per $Re=5000$}\label{fig:Nu_Re5000}
\end{figure}

\end{document}

enter image description here

enter image description here

  • Of course the problem is in text width=3cm – egreg Jan 17 '16 at 11:25
  • As @egreg said the text width is making the box for λacc much wider than the text would need, so the center of the node is not at the center of the displayed text. To debug this better you could add the draw=red option to the problematic nodes so you see exactly the shape of the box. – Bordaigorl Jan 17 '16 at 11:29
  • I think the original author used text width so that the λs would align, but It's much better to place them at the same x coordinate and use anchor=west – Bordaigorl Jan 17 '16 at 11:30
  • Could you explain what you mean by "the drawing is not centered"? Of course the drawing includes the help grid, which is centered it would seem. Try removing the \draw [help lines] (0,0) grid (10,10); line – Bordaigorl Jan 17 '16 at 11:32
  • It was centered but it seemed it wasn't because I wrongly used text width. Adding draw=red I was able to see that the box was way wider than the text and hence that the drawing was already centered. – Marco Jan 17 '16 at 12:31
4

1) The drawing is not centered

Well, it is centered. The problem is that your eye would like to see the central box centered instead of the whole bounding box, which includes the side text "piastra..." etc. To understand this, wrap your tikzpicture in a \fbox{....}: you'll see that the box is centered in the page. To fix this you can use the trim right option:

\begin{tikzpicture}[trim right=7cm]

which will consider everything drawn after the coordinate (7cm,0) outside the box. See the manual for more details on trims and bounding box.

2) The coordinate of λacc seems off

To debug this one I recommend trying adding a draw option to the problematic nodes so you see their shape.

\node [draw=red,text width=3cm,font=\footnotesize] at (2,2.05) {$\lambda_\mathrm{inc}$};
\node [draw=red,text width=3cm,font=\footnotesize] at (2,1.4) {$\lambda_\mathrm{biad}$};
\node [draw=red,text width=3cm,font=\footnotesize] at (2,0.5) {$\lambda_\mathrm{acc}$};

I would also add a node at crucial coordinate

\node[red] at (2,0.5) {x};

obtaining

red boxes

As you can see the nodes are much wider than needed and the coordinate they are placed at is their center. Now it makes sense. The original author of the picture did this by setting the width of the nodes artificially to a wide enough length with text width=3m. He did this so the nodes would be of the same width, otherwise, since they are placed at their center, they would not align.

A better solution to the alignment problem would be to remove text width and set the reference point for the placement to the west anchor:

\node [anchor=west,font=\footnotesize] at (.5,2.05) {$\lambda_\mathrm{inc}$};
\node [anchor=west,font=\footnotesize] at (.5,1.4) {$\lambda_\mathrm{biad}$};
\node [anchor=west,font=\footnotesize] at (.5,0.5) {$\lambda_\mathrm{acc}$};

would do what's required.

I encourage you to have a look at the manual for the positioning options to place nodes, and to how to set styles for more maintainable code.

  • I would like to have "piastra" on a line and "impingement" on the line below. If I try to use \\ \node [anchor=west,font=\footnotesize] at (7.6,5) {piastra\\impingement}; it gives me an error. – Marco Jan 17 '16 at 11:57
  • 1
    Look in the manual Section 17.4.3, there are several options on how to include multi-line text. Adding align=left should solve your issue. – Bordaigorl Jan 17 '16 at 12:07

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.