\documentclass{article}

\usepackage{blindtext}
\usepackage{multicol}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}
\usepackage{geometry}
\geometry{
	a4paper,
	noheadfoot=true,
	left=1.0in,
	right=1.0in,
	top=1.0in,
	bottom=1.0in
}

% url package
\usepackage{hyperref}
\usepackage{subcaption}

% Titling and Author
\title{Latex Tikz Examples, Relative Position on Page and Alignment}
\author{\href{https://fanwangecon.github.io/}{Fan Wang}\thanks{https://fanwangecon.github.io, repository: \href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}
\date{\today}

\begin{document}

\maketitle

\section{Relative Positioning}

\subsection{First line}
Using the code below, we draw from $x=0$ and $y=0$, to $x=1$ and $y=2$, the second point:
\begin{verbatim}
\draw (0,0) --(1,2);
\end{verbatim}
\bigskip
\begin{tikzpicture}
\draw (0,0) --(1,2);
\end{tikzpicture}

\subsection{Center Align Half Width Lines}
For lines below, we draw several partial page lines and align to page center:
\begin{verbatim}
\begin{center}
\begin{tikzpicture}
\draw (0,2) -- (0.25*\textwidth,2);
\draw (0,1) -- (0.5*\textwidth,1);
\draw (0,0) -- (0.75*\textwidth,0);
\end{tikzpicture}
\end{center}
\end{verbatim}
\bigskip
\begin{center}
\begin{tikzpicture}
\draw (0,2) -- (0.25*\textwidth,2);
\draw (0,1) -- (0.5*\textwidth,1);
\draw (0,0) -- (0.75*\textwidth,0);
\end{tikzpicture}
\end{center}

\subsection{Big line that fills page within margin}
Tikz coordinates are in cm. On A4 page, we have $21.0$ cm width by $29.7$ cm height. Each inch is $2.54$ cm. So with $1.0$ cm border on the left and on the right, we have $21-2.54\cdot2=15.92$, $15.92$ cm.
For lines below, we draw several full and partial page width lines:
\begin{verbatim}
\begin{center}
\begin{tikzpicture}
\draw (0,6) -- (7,6);
\draw (0,5) -- (15.92,5);
\draw (0,4) -- (0.45*\textwidth,4);
\draw (0,3) -- (0.5*\textwidth,3);
\draw (0,2) -- (0.9*\textwidth,2);
\draw (0,1) -- (\textwidth,1);
\end{tikzpicture}
\end{center}
\end{verbatim}
Note that we center the lines. Centering does not disrupt the coordinates, but just places entire tikz in the middle of page considering all plotted lines
\bigskip
\begin{center}
\begin{tikzpicture}
\draw (0,6) -- (7,6);
\draw (0,5) -- (15.92,5);
\draw (0,4) -- (0.45*\textwidth,4);
\draw (0,3) -- (0.5*\textwidth,3);
\draw (0,2) -- (0.9*\textwidth,2);
\draw (0,1) -- (\textwidth,1);
\end{tikzpicture}
\end{center}

\bigskip
For additional, information, see \href{https://tex.stackexchange.com/questions/58292/a-line-of-length-textwidth-in-tikz}{A line of length textwidth in TikZ}

\subsection{Box in the Middle of Page}
Now draw half width relative position box in the middle of pageFor lines below, we draw several full and partial page width lines:
\begin{verbatim}
\begin{center}
\begin{tikzpicture}
\draw (0,0) --
(0,0.5*\textwidth) --
(0.5*\textwidth, 0.5*\textwidth) --
(0.5*\textwidth, 0) -- (0, 0);
\end{tikzpicture}
\end{center}
\end{verbatim}
Note that the box is centered.
\bigskip
\begin{center}
\begin{tikzpicture}
\draw (0,0) -- (0,0.5*\textwidth) -- (0.5*\textwidth, 0.5*\textwidth) -- (0.5*\textwidth, 0) -- (0, 0);
\end{tikzpicture}
\end{center}

\subsection{Four Boxes Same Page in Larger Box}
There are four plots that I would like to draw together, four panels of tikz. We are defining height and width by textwidth, in this case textwidth is the width of each subfigure.

\begin{itemize}
    \item tikz page panels subplots
    \item latex subfigure
\end{itemize}

\begin{verbatim}
\def\fhratio{0.50}
\def\fwratio{1.0}
\begin{subfigure}[b]{0.49\textwidth}
    \begin{center}
    \begin{tikzpicture}
    \draw (0,0) --
        (0,\fhratio*\textwidth) --
        (\fwratio*\textwidth, \fhratio*\textwidth) --
        (\fwratio*\textwidth, 0) -- (0, 0);
    \draw
        (0.3*\fwratio*\textwidth,0.3*\fhratio*\textwidth) --
        (0.7*\fwratio*\textwidth,0.7*\fhratio*\textwidth);
    \end{tikzpicture}
    \end{center}
    \caption{Panel A}
    \label{fig:panela}
\end{subfigure}
\end{figure}
\end{verbatim}
Repeat this four timnes in a figure:
\def\fhratio{0.50}
\def\fwratio{1.0}
\begin{figure}[h]
    \centering
    \begin{subfigure}[b]{0.49\textwidth}
        \begin{center}
        \begin{tikzpicture}
        \draw (0,0) -- (0,\fhratio*\textwidth) -- (\fwratio*\textwidth, \fhratio*\textwidth) -- (\fwratio*\textwidth, 0) -- (0, 0);
        \draw (0.3*\fwratio*\textwidth,0.3*\fhratio*\textwidth) --(0.7*\fwratio*\textwidth,0.7*\fhratio*\textwidth);
        \end{tikzpicture}
        \end{center}
        \caption{Panel A}
        \label{fig:panela}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.49\textwidth}
        \begin{center}
        \begin{tikzpicture}
        \draw (0,0) -- (0,\fhratio*\textwidth) -- (\fwratio*\textwidth, \fhratio*\textwidth) -- (\fwratio*\textwidth, 0) -- (0, 0);
        \draw (0.3*\fwratio*\textwidth,0.3*\fhratio*\textwidth) --(0.7*\fwratio*\textwidth,0.7*\fhratio*\textwidth);
        \end{tikzpicture}
        \end{center}
        \caption{Panel B}
        \label{fig:panelb}
    \end{subfigure}
    \bigskip
    \\
    \begin{subfigure}[b]{0.49\textwidth}
        \begin{center}
        \begin{tikzpicture}
        \draw (0,0) -- (0,\fhratio*\textwidth) -- (\fwratio*\textwidth, \fhratio*\textwidth) -- (\fwratio*\textwidth, 0) -- (0, 0);
        \draw (0.3*\fwratio*\textwidth,0.3*\fhratio*\textwidth) --(0.7*\fwratio*\textwidth,0.7*\fhratio*\textwidth);
        \end{tikzpicture}
        \end{center}
        \caption{Panel C}
        \label{fig:panelc}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.49\textwidth}
        \begin{center}
        \begin{tikzpicture}
        \draw (0,0) -- (0,\fhratio*\textwidth) -- (\fwratio*\textwidth, \fhratio*\textwidth) -- (\fwratio*\textwidth, 0) -- (0, 0);
        \draw (0.3*\fwratio*\textwidth,0.3*\fhratio*\textwidth) --(0.7*\fwratio*\textwidth,0.7*\fhratio*\textwidth);
        \end{tikzpicture}
        \end{center}
        \caption{Panel D}
        \label{fig:paneld}
    \end{subfigure}
    \caption{Figure with Four Subfigures Each Containing Tikz Figure}\label{fig:tikztogether}
\end{figure}


\end{document}
