2

I'm working on a Python script to automatically draw pinout diagrams for IC's with Tikz. An example drawing with the TeX file obtained are shown below.

As you can see I'm almost done except for a small detail; the path joining the nodes overlaps the first node (PA1, PA2, etc.)

I've tried numerous things without success as Tikz seems to behave weirdly with my code.

enter image description here

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,external}

\begin{document}
\begin{preview}
\begin{tikzpicture}[transform shape,scale=0.8,
    pin/.style={draw,rectangle,rounded corners=1mm,fill=gray!50,minimum width=8mm},
    label/.style={draw,rectangle,rounded corners=1mm,minimum width=8mm}]

    % Constants
    \def\pps{8} % pps = pins per side
    \def\size{\pps * 0.75}
    \def\halfsize{\size / 2}
    \pgfmathsetmacro\side{2 * \size / 1.41}

    % Draw IC shape and name
    \node at (0,0) [minimum size=\side cm,diamond,fill=black!60,rounded corners=5mm] () {\LARGE STM32F103C8};
    \node at (0,\size / 1.8) [circle,inner sep=\size / 2,fill=black] () {};

    % Create pin nodes with numberings
    \newcounter{pin}\setcounter{pin}{0}

    \foreach \y/\angle/\dir in {-\halfsize/-45/1,-\halfsize/45/1,\halfsize/-45/-1,\halfsize/45/-1}{
        \begin{scope}[transform shape,rotate around={\angle:(0,0)}]
            \foreach \x in {1,...,\pps}
                \stepcounter{pin}
                \node at (\y - \dir * 0.3,{\dir * (\size / 2 - \size / (\pps + 1) * \x)}) [pin] (\thepin-0) {\large\thepin};
        \end{scope}
    }

    % Begin pin functions data
    % Pin 1
    \node[label,left=of 1-0,fill=gray] (1-1) {PA1};
    \node[label,left=of 1-1,fill=green] (1-2) {TIM1{\_}CH1};
    \node[label,left=of 1-2,fill=orange] (1-3) {ADC1{\_}CH2};
    \draw (1-0) [out=180,in=0] to (1-1)  -- (1-2)  -- (1-3) ; % <---- Problem is here

    % Pin 2
    \node[label,left=of 2-0,fill=gray] (2-1) {PA2};
    \node[label,left=of 2-1,fill=blue] (2-2) {DAC2};
    \node[label,left=of 2-2,fill=white] (2-3) {I2C{\_}SDL};
    \node[label,left=of 2-3,fill=orange] (2-4) {USART6{\_}RX};
    \draw (2-0) [out=180,in=0] to (2-1)  -- (2-2)  -- (2-3)  -- (2-4) ;

    %%%%%%%%
    % Rest of pins omitted to reduce clutter
    %%%%%%%%
\end{tikzpicture}
\end{preview}


\end{document}
2
  • Welcome! E.g. \draw (1-0) to[out=180,in=0] (1-1) (1-1) -- (1-2) to (1-3) ; fixes it.
    – user194703
    Sep 20, 2019 at 2:29
  • Thanks! I never would have guessed to repeat the (1-1).
    – jjpprr
    Sep 20, 2019 at 2:35

1 Answer 1

2

A very simple fix is to duplicate the first to node, i.e. to say

\draw (1-0) to[out=180,in=0] (1-1) (1-1) -- (1-2) to (1-3) ;

Please note that a to path, which relies on the topaths library, which however gets autoloaded, behaves somewhat different from --, not only in that you can bend the paths. The effect you are observing is that the to path connect to the correct point on the border (see the command \pgfpointshapeborder on p, 1123 of pgfmanual v3.1.4b), and then goes on from there. If you are saying that this behavior is not fully symmetrical, I agree.

Full MWE:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,external}

\begin{document}
\begin{preview}
\begin{tikzpicture}[transform shape,scale=0.8,
    pin/.style={draw,rectangle,rounded corners=1mm,fill=gray!50,minimum width=8mm},
    label/.style={draw,rectangle,rounded corners=1mm,minimum width=8mm}]

    % Constants
    \def\pps{8} % pps = pins per side
    \def\size{\pps * 0.75}
    \def\halfsize{\size / 2}
    \pgfmathsetmacro\side{2 * \size / 1.41}

    % Draw IC shape and name
    \node at (0,0) [minimum size=\side cm,diamond,fill=black!60,rounded corners=5mm] () {\LARGE STM32F103C8};
    \node at (0,\size / 1.8) [circle,inner sep=\size / 2,fill=black] () {};

    % Create pin nodes with numberings
    \newcounter{pin}\setcounter{pin}{0}

    \foreach \y/\angle/\dir in {-\halfsize/-45/1,-\halfsize/45/1,\halfsize/-45/-1,\halfsize/45/-1}{
        \begin{scope}[transform shape,rotate around={\angle:(0,0)}]
            \foreach \x in {1,...,\pps}
                \stepcounter{pin}
                \node at (\y - \dir * 0.3,{\dir * (\size / 2 - \size / (\pps + 1) * \x)}) [pin] (\thepin-0) {\large\thepin};
        \end{scope}
    }

    % Begin pin functions data
    % Pin 1
    \node[label,left=of 1-0,fill=gray] (1-1) {PA1};
    \node[label,left=of 1-1,fill=green] (1-2) {TIM1{\_}CH1};
    \node[label,left=of 1-2,fill=orange] (1-3) {ADC1{\_}CH2};
    \draw (1-0) to[out=180,in=0]  (1-1) (1-1) -- (1-2)  -- (1-3) ; % <---- Problem is here

    % Pin 2
    \node[label,left=of 2-0,fill=gray] (2-1) {PA2};
    \node[label,left=of 2-1,fill=blue] (2-2) {DAC2};
    \node[label,left=of 2-2,fill=white] (2-3) {I2C{\_}SDL};
    \node[label,left=of 2-3,fill=orange] (2-4) {USART6{\_}RX};
    \draw (2-0) to[out=180,in=0] (2-1) (2-1)  -- (2-2)  -- (2-3)  -- (2-4) ;

    %%%%%%%%
    % Rest of pins omitted to reduce clutter
    %%%%%%%%
\end{tikzpicture}
\end{preview}
\end{document}

enter image description here

1
  • Already replied to your comment, but thanks again!
    – jjpprr
    Sep 20, 2019 at 2:37

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.