2

I'm trying to convert a block diagram to latex source. What's the best approach to get exact shapes at exact locations and drawing interconnects between them? The shapes are just rectangles, circles, and ellipses. Nothing too complex os custom. I tried "node, draw" approach but latex seems to make its own decisions about the size.

EDIT: This is what I tried:

\documentclass[tikz,14pt,border=10pt]{standalone}
\usepackage{textcomp}
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{tikzpicture}[auto, thick, node distance=1px, >=triangle 45]
\node at (27, 14)[rectangle, minimum height=40pt]{A};
\node at (10, 17)[circle]{B};
\node at (40, 12)[circle]{C};
\node at (29, 25)[circle]{D};
\node at (11, 30)[circle]{E};

\end{tikzpicture}
\end{document}
  • What do you mean by node draw approach? Can you include your efforts so far – percusse Aug 25 '17 at 11:32
  • A TikZ \node will adjust the size to its content. – Torbjørn T. Aug 25 '17 at 11:35
  • @TorbjørnT. Yes. I'm more interested in the shape itself not the content inside it. Hence the search for alternate approaches. – SPRajagopal Aug 25 '17 at 11:38
  • Ehm, I don't understand what you mean. If you don't have any content you can set a minimum size (or minimum width/height, depending on shape). – Torbjørn T. Aug 25 '17 at 11:40
  • @TorbjørnT. Ehm, latex ignores minimum height for rectangles when I tried. Will post what I tried. – SPRajagopal Aug 25 '17 at 11:41
4

The border of a node is by default not drawn. If you want it to be, then add draw to the node options, i.e.

\node [draw] {a};

I would also recommend that you define styles for your different shapes. That makes it easier to modify a diagram, because you just modify the style, instead of the settings of each node. You can make a style with

\tikzset{NameOfStyle/.style={<list of settings>}}

an example is seen below.

Some other comments:

  • In the default classes, 14pt is not a valid option, you can choose between 10pt, 11pt and 12pt. As standalone uses article as the base class by default, you get the warning

    LaTeX Warning: Unused global option(s):
        [14pt].
    
  • Perhaps to some degree a question of preference, but the manual describes that the options to a node (the part in []) should come directly after node, not later, as in your code. It still works with your placement though. The manual says:

     \path node <foreach statements>[<options>](<name>)at(<coordinate>){<node contents>} ...;
    
  • While the arrows library still works, it is considered deprecated in favor of the newer arrows.meta library, which is described in section 16.5 of the manual.

  • The node distance key that you've used is only relevant if you place one node relative to another. To do that, add

    \usetikzlibrary{positioning}
    

    and then if you have \node (a) {aaaa};, you can say

     \node[right=of a] {b};
    

    to place this second node the distance defined by node distance right of the first node.

output of code

\documentclass[tikz,12pt,border=10pt]{standalone}
\usepackage{textcomp}
\usetikzlibrary{shapes,arrows.meta}
\tikzset{
  MyBox/.style={draw,minimum height=40pt,minimum width=2cm},
  MyCirc/.style={draw,circle,minimum size=50pt}
}
\begin{document}
\begin{tikzpicture}[auto, thick, node distance=1px, >=Triangle]
\node [MyBox] (a) at (27, 14) {A};
\node [MyCirc] (b) at (10, 17) {B};
\node [MyCirc] (c) at (40, 12) {C};
\node [MyCirc] (d) at (29, 25) {D};
\node [MyCirc] (e) at (11, 30) {E};

\draw (a) -- (b) -- (d) -- (c) -- (e);
\end{tikzpicture}
\end{document}
| improve this answer | |
  • thanks a ton. Makes sense now. Related, there's a lack of decent and exhaustive documentation of all the options in tikz nodes, draw, etc. A bunch of examples not cutting it from the wiki page for me. – SPRajagopal Aug 25 '17 at 11:55
  • Also related, but how do you specify the minimum size in px? Seems to throw an unknown symbol error for me – SPRajagopal Aug 25 '17 at 11:56
  • @SPRajagopal Seems you can't, but setting a size in pixels doesn't really make sense either in this context (to me at least). – Torbjørn T. Aug 25 '17 at 12:08
  • @SPRajagopal px is actually available in pdflatex, though it doesn't work in that context in TikZ (don't know why). But that doesn't really matter, as 1px is set equal to 1bp (big point, or PostScript point, 1/72 in), and bp works as a unit for minimum size. See tex.stackexchange.com/questions/41370/… – Torbjørn T. Aug 25 '17 at 12:11
1

The following MWE is working for me. I am using minimum height and width also along with minimum text width.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[
        block/.style={rectangle, thick, draw, minimum height=9mm, minimum width=10mm,text width=15mm,align=center},
        connection/.style={->,thick},]
        \node[block] (A)    at (1.5,0)  {Block A};
        \node[block] (B)    at (3.5,0)  {Block B};

        \draw[connection] (A.east) -- (B.west);
    \end{tikzpicture}
\end{document}

output of the MWE

| improve this answer | |

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.