5

I want to draw following line, its tip at right), as follows:

image 1 image 2


tex file:

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \draw (0,0) grid (1,-1);
    \draw [semithick](0.8,-0.1)--+(-0.6,-0.7);
\end{tikzpicture}
\end{document}

enter image description here

Here I was not able to draw perfectly symmetric line inside the box and couldn't draw the tip of the line as shown above.

Could be related to: How to change the tip of line in tikz

1 Answer 1

9

Use the arrows.meta library with Triangle Cap to get those line tips.

enter image description here

I changed your grid to rectangle to get nicer corners. To place the line along the diagonal, you can draw from corner to corner and use shorten as in the code below:

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,-1);
    \draw[Triangle Cap-Triangle Cap, shorten <=2mm, shorten >=2mm] [semithick](0,-1)--++(1,1);
\end{tikzpicture}
\end{document}
4
  • Is it also possible to center the line in the box?
    – alper
    Commented Oct 6, 2022 at 23:30
  • 2
    Given the grid coordinates, you could use (.2,-.8)--++(.6,.6), or use (0,-1)--++(1,1) and add shorten <=2mm, shorten >=2mm.
    – Sandy G
    Commented Oct 6, 2022 at 23:33
  • Should I write shorten <=2mm, shorten >=2mminside the draw[]?
    – alper
    Commented Oct 7, 2022 at 11:09
  • 1
    @alper: I edited my response.
    – Sandy G
    Commented Oct 7, 2022 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .