2

A rectangle and a square appeared when I used the command \draw[clip], but I only need the inner square. What should I do to remove the outer rectangle? When I used \path, both rectangle and square disappeared. enter image description here

    \documentclass[a4paper, 11pt]{article}

\usepackage[a4paper,
    tmargin=2cm,%
    rmargin=2cm,%
    bmargin=2cm,%
    lmargin=2cm,
    vscale=1,%
    hscale=1]{geometry}

\usepackage{tikz}

% only used for the example
\newlength{\skiplength}
\setlength{\skiplength}{1cm}
\setlength{\parskip}{\skiplength}
\setlength{\parindent}{0pt}

\begin{document}
\centering{
A1\\
\vspace{\skiplength}
\begin{tikzpicture}[x=11.1cm, y=7.5cm]
    \draw [clip=true model=individual] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
         (2cm, 0.5cm)
        [rounded corners=5pt] -- (2cm, 2.5cm)
        [rounded corners=10pt] -- (4cm, 2.5cm)
        [rounded corners=0.5cm] -- (4cm, 0.5cm)
        [sharp corners] -- cycle;

    \node[anchor=south west,%
        inner sep=0,%
        outer sep=0pt] (image) at (0, 0) {\includegraphics{a1_03}};
\end{tikzpicture}
}



\end{document} 
dozer
  • 841
  • 1
    Something wrong happened to your code, all [ and ] has been replaced by \[ and \], would you mind fixing that? – Torbjørn T. Feb 24 '17 at 13:32
  • 2
    Yes, but you didn't fix the one thing I actually suggested you fix. For example, you have \documentclass\[ ... \]{article}, which should be \documentclass[...]{article}, and same for all the other [ and ] it seems. (This happens occasionally, don't know why. I assume those backslashes are not there in your .tex file) – Torbjørn T. Feb 24 '17 at 13:46
  • thank you, I don't know where these codes come from. – dozer Feb 24 '17 at 13:59
  • 1
    off-topic, but \centering does not take arguments, so it should be \centering A1 and not \centering{ A1 – samcarter_is_at_topanswers.xyz Feb 24 '17 at 14:01
  • Can you please also fix all the other \[...\]? – samcarter_is_at_topanswers.xyz Feb 24 '17 at 14:02
  • It happens sometimes, as I said I don't know why, a bug of the site itself probably. I also said it happened for all [ and ], not just the first one. – Torbjørn T. Feb 24 '17 at 14:05
  • Ok, I didn't know there were so many errors, I thought there was only one this type error. – dozer Feb 24 '17 at 14:15
  • 1
    By the way, I think I figured out why you got all those extra backslashes: you inserted an image with the code still selected. If you paste in some code, select it and hit the {} button, it is highlighted as code. If you then immediately clicks the button to insert in image (without first deselecting the code), the brackets are escaped with backslashes, probably because they're used in the Markdown for inserting images. So not really a bug, just user error: always deselect the code block before you insert an image. – Torbjørn T. Feb 25 '17 at 09:38
  • you are right. I also think so. – dozer Feb 25 '17 at 10:11

1 Answers1

3

based on https://tex.stackexchange.com/a/290508/36296

Is this what you are trying to do?

\documentclass[a4paper, 11pt]{article}

\usepackage[a4paper,
    tmargin=2cm,%
    rmargin=2cm,%
    bmargin=2cm,%
    lmargin=2cm,
    vscale=1,%
    hscale=1]{geometry}

\usepackage{tikz}

% only used for the example
\newlength{\skiplength}
\setlength{\skiplength}{1cm}
\setlength{\parskip}{\skiplength}
\setlength{\parindent}{0pt}

\usetikzlibrary{graphs,graphs.standard}

\tikzset{
    clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey 
  invclip/.style = {
    clip,
    insert path = [clip even odd rule]{
        [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
    }
  }
}

\begin{document}
\centering{
A1\\
\vspace{\skiplength}
\begin{tikzpicture}[x=11.1cm, y=7.5cm]
    \begin{pgfinterruptboundingbox}        \clip[invclip] (2cm, 2.5cm)  [rounded corners=5pt]  -- (4cm, 2.5cm) -- (4cm, 0.5cm) -- (2cm, 0.5cm) -- (2cm, 2.5cm) [sharp corners] --  cycle;
    \end{pgfinterruptboundingbox}
    \node[anchor=south west,%
        inner sep=0,%
        outer sep=0pt] (image) at (0, 0) {\includegraphics[width=8cm]{example-image}};
        \draw[red, line width = 4pt] (2.1cm, 2.5cm)  [rounded corners=5pt]  -- (4cm, 2.5cm) -- (4cm, 0.5cm) -- (2cm, 0.5cm) -- (2.cm, 2.5cm) [sharp corners] --  cycle;
\end{tikzpicture}
}



\end{document} 

enter image description here