4

here's my MWE:

\documentclass[a5paper]{book} 
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.misc,calc}

\begin{document}

      \begin{tikzpicture}[overlay,remember picture]
      \node[
                fill=gray,
                inner sep=0pt,
                rounded rectangle,
                rounded rectangle west arc=none,
                rounded corners=15pt,
                text width=20mm,
        text height=20mm,
                align=center,
                anchor=north east] at
                    ($ (current page.north east) + (-14mm,-20mm) $){};
      \end{tikzpicture}

\end{document}

\end{document}

I'd like to make this shape look like the one at the bottom. How can I manage this?

enter image description here

Moldevort
  • 1,295
  • I think this is duplicate http://tex.stackexchange.com/questions/28115/rounded-corners-only-at-one-side-of-a-tikz-node – percusse Sep 02 '14 at 10:05
  • @percusse I sure can't reproduce it using that solution. :D – 1010011010 Sep 02 '14 at 10:15
  • Maybe rounded rectangle and rounded corners are incompatible – Harald Sep 02 '14 at 10:23
  • Moldevort, do you only need the shape? – 1010011010 Sep 02 '14 at 10:23
  • I only need this shape. I don't want the kind of corners I get when I use "rounded rectangle" only. – Moldevort Sep 02 '14 at 10:25
  • I've checked the shape; you can't alter the curvature of the arc. It only makes a convex curve and nothing else. You are overriding the drawing options with 15pt hence the strange curve – percusse Sep 02 '14 at 10:41
  • @Moldevort: Not related to your question but maybe interesting for the implementation of a thumb index: http://tex.stackexchange.com/q/57031/4918 – Tobi Sep 02 '14 at 12:50

3 Answers3

5

It is reasonably straightforward to hack the rectangle shape to add four ifs to control whether the corner rounding is applied at each corner:

\documentclass[tikz,border=5]{standalone}
\newif\ifpgfshaperectangleroundnortheast
\newif\ifpgfshaperectangleroundnorthwest
\newif\ifpgfshaperectangleroundsoutheast
\newif\ifpgfshaperectangleroundsouthwest
\pgfkeys{/pgf/.cd,
  rectangle round north east/.is if=pgfshaperectangleroundnortheast,
  rectangle round north west/.is if=pgfshaperectangleroundnorthwest,
  rectangle round south east/.is if=pgfshaperectangleroundsoutheast,
  rectangle round south west/.is if=pgfshaperectangleroundsouthwest,
  rectangle round north east, rectangle round north west,
  rectangle round south east, rectangle round south west,
}
\makeatletter
\def\pgf@sh@bg@rectangle{%
  \pgfkeysgetvalue{/pgf/outer xsep}{\outerxsep}%
  \pgfkeysgetvalue{/pgf/outer ysep}{\outerysep}%
  \pgfpathmoveto{\pgfpointadd{\southwest}{\pgfpoint{\outerxsep}{\outerysep}}}%
  {\ifpgfshaperectangleroundnorthwest\else\pgfsetcornersarced{\pgfpointorigin}\fi%
    \pgfpathlineto{\pgfpointadd{\southwest\pgf@xa=\pgf@x\northeast\pgf@x=\pgf@xa}{\pgfpoint{\outerxsep}{-\outerysep}}}}%  
  {\ifpgfshaperectangleroundnortheast\else\pgfsetcornersarced{\pgfpointorigin}\fi%  
    \pgfpathlineto{\pgfpointadd{\northeast}{\pgfpoint{-\outerxsep}{-\outerysep}}}}%
  {\ifpgfshaperectangleroundsoutheast\else\pgfsetcornersarced{\pgfpointorigin}\fi%  
    \pgfpathlineto{\pgfpointadd{\southwest\pgf@ya=\pgf@y\northeast\pgf@y=\pgf@ya}{\pgfpoint{-\outerxsep}{\outerysep}}}}%
  {\ifpgfshaperectangleroundsouthwest\else\pgfsetcornersarced{\pgfpointorigin}\fi%  
    \pgfpathclose}}
\begin{document}
\begin{tikzpicture}[every node/.style={draw, rectangle, rounded corners=1ex}]
\node at (0,0) {A};
\node [rectangle round north east=false, rectangle round south east=false] at (1,0) {B};
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
4

You can use \clip:

\documentclass[a5paper]{book}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.misc,calc}

\begin{document}

      \begin{tikzpicture}[overlay,remember picture]
      \clip ($ (current page.north east) + (-19mm,-20mm) $) rectangle ($ (current page.north east) + (-14mm,-20mm) + (-30mm,-20mm) $);
      \node[
                fill=gray,
                inner sep=0pt,
                rectangle,
                rounded corners=15pt,
                text width=30mm,
        text height=20mm,
                align=center,
                anchor=north east] at
                    ($ (current page.north east) + (-14mm,-20mm) $){};
      \end{tikzpicture}

\end{document}

enter image description here

If you want it at the paper edge, simply do this:

\documentclass[a5paper]{book}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.misc,calc}

\begin{document}

      \begin{tikzpicture}[overlay,remember picture]
      \node[
                fill=gray,
                inner sep=0pt,
                rounded rectangle,
                rounded rectangle west arc=none,
                rounded corners=15pt,
                text width=20mm,
        text height=20mm,
                align=center,
                anchor=north east] at
                    ($ (current page.north east) + (0mm,-20mm) $){};
      \end{tikzpicture}

\end{document}
1

A dirty solution if I ever saw one. But I guess it produces the desired effect.

http://i.imgur.com/EoCRn6L.png?1

\documentclass[a5paper]{book} 
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.misc,calc}

\begin{document}

\begin{tikzpicture}[overlay, remember picture]
\node[anchor=north east] at ($ (current page.north east) + (-14mm,-20mm) $){\begin{tikzpicture}
\draw[fill=gray,draw=none,
                rounded corners=15pt] (0,0)  -- (-3,0) -- (-3,-2)
[rounded corners=0pt] -- (0,-2) -- cycle;
\end{tikzpicture}};
\end{tikzpicture}

\end{document}

Specifically for thumbindices, you could use something like this:

\documentclass[a5paper]{book} 
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.misc,calc}

\begin{document}

\begin{tikzpicture}[overlay, remember picture,every node/.style={xshift=.05in,yshift=.05in,anchor=north east}]]
\foreach \i/\col in {0/gray,20/lightgray,40/orange,60/yellow} {
\node at ($ (current page.north east) + (0mm,{-\i mm}) $){
\begin{tikzpicture}
\draw[fill=\col,draw=none,
                inner sep=0pt,
                rounded corners=15pt, ] (0,0)  -- (-3,0) -- (-3,-2)
[rounded corners=0pt] -- (0,-2) -- cycle;
\end{tikzpicture}};
}
\end{tikzpicture}

\end{document}
1010011010
  • 6,357
  • Hm.. the aligning is not working properly. When I set (-14mm,-20mm) to (0mm,0mm) there's a little space above and right of it. How come? – Moldevort Sep 02 '14 at 11:01
  • @Moldevort Good question. I'm looking into it. The offset is -.05in in both x and y direction. Preliminary answer: I suspect this is caused by the fact that the enclosed tikzpicture in the node has white space around it. – 1010011010 Sep 02 '14 at 11:11
  • I will use this shape for thumbindices so I need to align them very precisely. Is there any way to prevent this space? Elsewise I will have to substract 0.05in for each aligning – Moldevort Sep 02 '14 at 11:17
  • Check my updated answer. Remember that it's a huge workaround. – 1010011010 Sep 02 '14 at 11:31
  • Try to avoid nesting tikzpictures: it is generally advisable. Instead, you can draw the shape via the pic operation available from TikZ version 3.0.0. – Claudio Fiandrino Sep 02 '14 at 11:43
  • I've tried adjusting the size by adding text width and text height but haven't suceeded. Where ecaxtly do I have to put it?

    @ClaudioFiandrino Could you post an example? I'm not that experienced.

    – Moldevort Sep 02 '14 at 11:58