13

I refer to this question: LaTeX Photo With Rounded Corners

I would like to round the corners of a Tikz node (which actually is a fitted node around two other nodes), but would like to have an additional black frame around it. If I just draw a black rounded frame around my node, it has to be very thick depending on the amount of clipping.

Is there a solution where I first remove the corners and then draw a black frame around the "rounded" node?

Here is an example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}

\begin{document}
\begin{tikzpicture}
    \node [inner sep=0pt,minimum size=4.0cm,outer sep=0pt,clip] (pict) at (0,0) {\includegraphics[width=4.0cm]{images/black.png}};
    \node [inner sep=0pt,minimum size=4.0cm,outer sep=0pt,clip,below = of pict] (pict2) at (0,0) {\Huge Hello};
    \node[draw=red,thick,fit=(pict)(pict2),rounded corners=.55cm,inner sep=2pt]    {};
\end{tikzpicture}
\end{document}
12
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}
   \node [inner sep=0pt,,outer sep=0pt,clip,rounded corners=0.5cm] (pict) at (0,0) {\includegraphics[width=4.0cm]{example-image-a}};
   \node[draw=red,thick,fit=(pict),rounded corners=.55cm,inner sep=2pt]    {};

   \node [inner sep=0pt,,outer sep=0pt,clip,rounded corners=0.5cm] (pict1) at (6,0) {\includegraphics[width=5.0cm]{example-image-b}};
   \node[draw=olive,thick,fit=(pict1),rounded corners=.55cm,inner sep=2pt]    {};
\end{tikzpicture}
\end{document}

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}

\begin{document}
\begin{tikzpicture}
    \clip [rounded corners=.5cm] (0,0) rectangle (4,8);
    \node [inner sep=0pt,minimum size=4cm,outer sep=0pt] (pict) at (2,6)
         {\includegraphics[height=4.0cm]{example-image-a}};
    \node [draw,inner sep=0pt,minimum size=4cm,outer sep=0pt,clip] (pict2) at (2,2)
         {\includegraphics[height=4.0cm]{example-image-b}};
    \draw [red,line width=1pt,rounded corners=.5cm]
        ([shift={(0.5\pgflinewidth,0.5\pgflinewidth)}]0,0) rectangle
        ([shift={(-0.5\pgflinewidth,-0.5\pgflinewidth)}]4,8);
\end{tikzpicture}
\end{document}

enter image description here

  • Ok maybe I missed something. Basically I have three nodes. Two are aligned vertically and a third one is fitted around them. The third one is the one which should have the round corners. The problem is, that I cannot use round corners for the inner two nodes, as the upper one is supposed to have only round nodes at the top, and the lower one at the bottom. I added an example to the question. – Simon Nov 7 '14 at 12:43
  • Thanks. Your second solution brought me to my own. The problem with your solution (for me) is, that all sizes have to be known in advance. I fit a white node to both inner nodes and then use these coordinates and the calc library for drawing the black border. – Simon Nov 8 '14 at 10:26
3

An alternative is the use of corners of current bounding box, form an arc area to fill with a white color to mimic a clip. Changing the \path commands to \draw commands sees the arc areas.

enter image description here

Code

\documentclass[border=10pt]{standalone}
%\usepackage[]{graphicx}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}
\begin{document}
\begin{tikzpicture}
\node [inner sep=0pt,minimum size=4.0cm,outer sep=0pt,clip] (pict) at (0,0)  {\includegraphics[width=4.0cm]{example-image-a}};

\path[fill=white] ([yshift=-14pt]current bounding box.north west) -- ++(1,0) arc(90:180:1) --cycle; %<--
\path[fill=white] ([yshift=-14pt]current bounding box.north east) -- ++(-1,0) arc (90:0:1) --cycle; %<--

\node [inner sep=0pt,minimum size=4.0cm,outer sep=0pt,below = of pict,clip] (pict2) at (0,0) {\includegraphics[width=4.0cm]{example-image-b}};

\path[fill=white] ([yshift=14pt]current bounding box.south west) -- ++(1,0) arc(-90:-180:1) --cycle; %<--
\path[fill=white] ([yshift=14pt]current bounding box.south east) -- ++(-1,0) arc(-90:0:1) -- cycle; %<--

\node[draw=red,thick,fit=(pict)(pict2), rounded corners=.55cm,inner sep=2pt]  {};
\end{tikzpicture}
\end{document}
3

Here is my own solution. It was heavily inspired by Harish Kumar's answer. I am open for improvements ;-)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,calc}

\begin{document}
\begin{tikzpicture}[node distance=0]
    \node [inner sep=0pt,outer sep=0pt] (pict)
        {\includegraphics[height=4.0cm]{example-image-a}};
    \node [inner sep=0pt,outer sep=0pt,below = of pict] (pict2)
        {\includegraphics[height=4.0cm]{example-image-b}};              
    \node [draw=red,rounded corners=1pt,line width=3pt,
        inner sep=0pt,outer sep=0pt,fit=(pict)(pict2)] (pict3) {};
    \draw [blue,line width=1pt,rounded corners=1pt]
        ($(pict3.south west)+(\pgflinewidth,\pgflinewidth)$) rectangle
        ($(pict3.north east)-(\pgflinewidth,\pgflinewidth)$);
\end{tikzpicture}
\end{document}

Solution

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.