0

I want to make a line, like this one.

\documentclass{article}
\usepackage(tikz}
\begin{tikzpicture}
   \draw (0,0) -- (1,0.5)
\end{tikzpicture}

For example, I draw a line that starts from coordinate (0,0) to (1,0.5). It should be like this one.

enter image description here

(Note: This is a picture that I draw in Paint)

Unfortunately, I don't know how to denote the points (for example A is the coordinate of (0,0) and B is the coordinate of (1,0.5).).

Another example, I copied one of the codes in this link: How to draw parallelepiped and cube with LaTeX, and then I replace it as

\begin{center}
    \begin{tikzpicture}[every edge quotes/.append style={auto, text=black}]
  \pgfmathsetmacro{\cubex}{3}
  \pgfmathsetmacro{\cubey}{3}
  \pgfmathsetmacro{\cubez}{3}
  \draw [draw=, every edge/.append style={draw=black, densely dashed, opacity=.5}, fill=white]
    (0,0,0) coordinate (o) -- ++(-\cubex,0,0) coordinate (a) -- ++(0,-\cubey,0) coordinate (b) edge coordinate [pos=1] (g) ++(0,0,-\cubez)  -- ++(\cubex,0,0) coordinate (c) -- cycle
    (o) -- ++(0,0,-\cubez) coordinate (d) -- ++(0,-\cubey,0) coordinate (e) edge (g) -- (c) -- cycle
    (o) -- (a) -- ++(0,0,-\cubez) coordinate (f) edge (g) -- (d) -- cycle;
  \path [every edge/.append style={draw=black, |-|}]
    (b) +(0,-5pt) coordinate (b1) edge ["8cm"'] (b1 -| c)
    (b) +(-5pt,0) coordinate (b2) edge ["8cm"] (b2 |- a)
    (c) +(3.5pt,-3.5pt) coordinate (c2) edge ["8cm"'] ([xshift=3.5pt,yshift=-3.5pt]e)

And I don't know how to denote point (for example let ABCDEFGH be a cube).

1 Answers1

3

Welcome to TeX.SE!

Just add nodes above given coordinates:

\documentclass[border=3.141593]{standalone}
\usepackage{tikz}

\begin{document} \begin{tikzpicture} \draw (0,0) node[above] {A} -- (2,1) node[above] {B}; \end{tikzpicture} \end{document}

[![enter image description here][1]][1]

Addendum:

  • You are quite demanding: full service for two equal problems.
  • At the cube the adding of labels is the same problem as it is already solved for the line, in the answer above. So you only need to add labels to coordinates accordingly
  • However, your code for the cube is erroneous, so I guess that this is your main problem at it.
  • Since you are novice, I made exception and clean-up your code for cube and add desired labels for all corners (next time your question probably will be closed as Needs details or clarity).
  • Please, always provide complete small document called MWE (Minimal Working Example), which reproduce your problem and not only uncomplete code fragment. Many times problems has source in MWE preamble.
  • And finally, please one problem per question.

MWE for the cube can be for example:

\documentclass[border=3.141593]{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}
\usepackage{siunitx}

\begin{document} \begin{tikzpicture}[ every edge quotes/.style={auto, font=\footnotesize, sloped, inner sep=2pt}, every label/.style = {inner sep=1pt, font=\scriptsize} ] \pgfmathsetmacro{\cubex}{3} \pgfmathsetmacro{\cubey}{3} \pgfmathsetmacro{\cubez}{3} \draw (0,0,0) coordinate[label=below left:A] (a) -- ++ ( \cubex,0,0) coordinate[label=below right:B] (b) -- ++ (0, \cubey,0) coordinate[label=above left:C] (c) -- ++ (-\cubex,0,0) coordinate[label=above left:D] (d) -- cycle (d) -- ++ (0,0,-\cubez) coordinate[label=above right:E] (e) -- ++ ( \cubex,0,0) coordinate[label=above right:F] (f) -- ++ (0,-\cubey,0) coordinate[label=above right:G] (g) -- (b) (c) -- (f); \fill[red!30, semitransparent] (a) -- (d) -- (e) -- (f) -- (g) -- (b) -- cycle; \draw[densely dashed] (a) -- (e |- g) coordinate[label=above right:H] (h) -- (g) (h) -- (e); \path[draw=cyan, |-|] ([yshift=-3mm] a) edge ["\qty{8}{cm}"'] ([yshift=-3mm] b) ([xshift=-3mm] a) edge ["\qty{8}{cm}" ] ([xshift=-3mm] d) ([shift={(3mm,-3mm)}] b) to ["\qty{8}{cm}"'] ([shift={(3mm,-3mm)}] g) ; \end{tikzpicture} \end{document}

[![enter image description here][2]][2]

Edit: Added is siunitx package and lenght is written as \qty{8}{cm}. [1]: https://i.stack.imgur.com/64Npi.png [2]: https://i.stack.imgur.com/1NlAR.png

Zarko
  • 296,517
  • What about the codes to make a cube? – Dedhert . Jr Aug 04 '21 at 02:55
  • @Dedhert.Jr one problem for question please! BTW, second code is quite erroneous, to clean up it, I need more time. – Zarko Aug 04 '21 at 03:00
  • Well. I appreciate your work. Thank you. – Dedhert . Jr Aug 04 '21 at 04:10
  • By the way, I don't know how to use \path. Is there a link for further information? – Dedhert . Jr Aug 04 '21 at 04:11
  • @Dedhert.Jr, please read "TikZ & PGF Manual". It is part of your package installation. You can also find on CTAN (use Google). Documentation is huge, but for start should be sufficient to read first tutorial and than part III: "TikZ ist kein Zeichenprogramm". Also can be helpful "Minimal introduction to TikZ (unofficial)" which you can find on CTAN too. – Zarko Aug 04 '21 at 04:19
  • Thank you for the information. – Dedhert . Jr Aug 04 '21 at 04:34
  • +1 and haha for You are quite demanding :) – Dr. Manuel Kuehner Aug 04 '21 at 04:47
  • I have a question here. For command \path, how do I use the line (like the previous problem) from A to B? Maybe if you give some advice, I'd like to practice it to draw two-dimensional shapes using the command \path for measuring. – Dedhert . Jr Aug 04 '21 at 05:28
  • @Dedhert.Jr, sorry, t don't undestand you, what is the problem. IN answer you have examples has to use path as well \draw command. A latter is actually abrevation for \path[draw]. See section "11.3 Actions on Paths", page 125 in TikZ & PGF Manual for Version 3.1.9a. – Zarko Aug 04 '21 at 05:37
  • @Dedhert.Jr, you may explore https://texample.net/. There are many examples of the use of TikZ. – Zarko Aug 04 '21 at 05:44