3

I use the following Latex script

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

\begin{document}

\begin{tikzpicture}
\filldraw[fill=gray!40!white, draw=black] (0,0) rectangle (4,2);
\node[black](dot) at (2,1) {\textbullet};
\node[below=0cm of dot]  {\small{$x_a = (2,1)$}};
\end{tikzpicture} 

\end{document}

To get:

Rectangle

Is there a way to add the corner coordinates as well? For example, I would like to see (0,0) in the lower-left corner.

2 Answers 2

1

Sure.

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

\begin{document}

\begin{tikzpicture}
\filldraw[fill=gray!40!white, draw=black] (0,0) 
node[black,label={[font=\small]below:$x_0 = (0,0)$}](dot0){\textbullet}
rectangle (4,2)
node[black,midway,label={[font=\small]below:$x_a = (2,1)$}](dot){\textbullet};
\end{tikzpicture} 

\end{document}

enter image description here

Or

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

\begin{document}

\begin{tikzpicture}[bullet/.style={node contents={\textbullet},
label={[font=\small]below:#1}}]
\filldraw[fill=gray!40!white, draw=black] (0,0) 
node[bullet={$x_0=(0,0)$}] 
rectangle (4,2) node[midway,bullet={$x_a=(2,1)$}];
\end{tikzpicture} 

\end{document}
3
  • Many thanks!!! a Jun 1, 2019 at 15:59
  • Also, I know this is not relevant, but just want to know: could I somehow give constraint $x_2 \geq 0, x_1 \leq 4$ ,etc. and generate such a graph? It wold be harder, right? Jun 1, 2019 at 16:06
  • @independentvariable Not necessarily, it depends on what precisely you want to achieve. Here is a question on this with answers.
    – user121799
    Jun 1, 2019 at 16:33
2

A PSTricks solution only for fun purposes!

enter image description here

\documentclass[pstricks,12pt,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(-1,-1)(4,2)
    \psframe[fillstyle=solid,fillcolor=lightgray](0,0)(4,2)
    \pstGeonode[PosAngle={-90},PointName={{x_0=(0,0)},{x_a=(2,1)}}](0,0){O}(2,1){A}
\end{pspicture}
\end{document}

You must log in to answer this question.

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