1

I have a plot a graph and I need to crop it like an arc. Can anybody help me that how I can figure it out using latex?

Thank you.enter image description here

  • You could rotate it, clip it and rotate it back. adjustbox is of great help here (hint: use \adjustimage instead of \includegraphics and Clip instead of clip). However, including it into a tikzpicture and add a clipping path would be more flexibler and maybe even easier. – Martin Scharrer Jan 10 '18 at 7:19
  • Dear Martin. I have not worked with adjustbox . Could you please provide a code for your suggestion? – HS8637 Jan 10 '18 at 7:23
  • Generate note: the clipped away part is still stored in the final PDF but is not displayed. Using advanced PDF tools someone could extract the original full image, so in-TeX clipping should never be used to hide secret information etc. In that cases the image should be clipping using an external image manipulation program first. – Martin Scharrer Jan 10 '18 at 7:42
3

I think the best way is to use tikz and clip it there using a clipping path. For this you need to save the image into a savebox first so you know the dimensions. Then you first limit the bounding box to the original image size and add a clipping path.


To clip it using an arc use the follow code:

\documentclass{article}

\usepackage{tikz}

\newsavebox\mysavebox

\begin{document}

\begin{tikzpicture}
    \savebox\mysavebox{\includegraphics[width=.9\textwidth]{example-image-1x1}}
    \path [use as bounding box] rectangle (\wd\mysavebox, \ht\mysavebox);
    \path [draw,clip] (0, 0) arc [start angle=180, end angle=90, radius=\wd\mysavebox] -- (\wd\mysavebox, 0) -- cycle;
    \node [anchor=south west, inner sep=0pt, outer sep=0pt] at (0,0) {\usebox\mysavebox};
\end{tikzpicture}

\end{document}

enter image description here


To clip the image using a circle use the following code:

\documentclass{article}

\usepackage{tikz}

\newsavebox\mysavebox

\begin{document}

\begin{tikzpicture}
    \savebox\mysavebox{\includegraphics[width=.9\textwidth]{example-image-1x1}}
    \path [use as bounding box] rectangle (\wd\mysavebox, \ht\mysavebox);
    \path [clip] (.5\wd\mysavebox, .5\ht\mysavebox) circle (.5\wd\mysavebox);
    \node [anchor=south west, inner sep=0pt, outer sep=0pt] at (0,0) {\usebox\mysavebox};
\end{tikzpicture}

\end{document}

enter image description here


You can also get an angled clipping path using polar coordinates. I'm using (45:100) here to have 45 degrees. The radius is 100cm so that it is larger than the image, which works as we fix the bounding box beforehand, so that doesn't increase the resulting picture size.

As the clipping path can be arbitrary you have a lot of freedom.

\documentclass{article}

\usepackage{tikz}

\newsavebox\mysavebox

\begin{document}

\begin{tikzpicture}
    \savebox\mysavebox{\includegraphics[width=.9\textwidth]{example-image}}
    \path [use as bounding box] rectangle (\wd\mysavebox, \ht\mysavebox);
    \path [clip] (0,0) -- (45:100) -- (0:100) -- cycle;
    \node [anchor=south west, inner sep=0pt, outer sep=0pt] at (0,0) {\usebox\mysavebox};
\end{tikzpicture}

\end{document}

enter image description here

  • Dear Martin. As is shown at the end of the plot is not round like a circle. How can it be cropped like that? – HS8637 Jan 10 '18 at 7:51
  • @HadiSobhani: Ok, I misunderstood, the 45 degrees "line" in the image looked like you wanted it cropped like this. – Martin Scharrer Jan 10 '18 at 8:01
  • Yes, I wanted to crop that image at 45 degrees like a sector of a circle. – HS8637 Jan 10 '18 at 8:04
  • @HadiSobhani: Just add a suitable clipping path. I added some examples. – Martin Scharrer Jan 10 '18 at 8:10
  • Dear Martin Scharrer, Thank you so much. I worked out :). – HS8637 Jan 10 '18 at 10:44

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.