1

I added different values of hspace to manually align them

My code excluding preamble (don't judge please):

\subsection{Inverse Hyperbolic Trigonometric Identities}
\raggedright\setlength{\parindent}{45pt}
    \begin{enumerate}[align=left,widest=a,labelindent=16mm,leftmargin=!]
    \incrvariable\x
    \setcounter{enumi}{\x}
    \item%194
        $
        \begin{aligned}[t]
        \sinh(\cosh^{-1}{x})=\sqrt{x^2-1} \hspace{20pt} &\text{Domain: } [1,\infty) \hspace{26.5pt} &&\text{Range: } [0,\infty)
        \end{aligned}
        $
    \incrvariable\x
    \item%195
        $
        \begin{aligned}[t]
        \cosh(\sinh^{-1}{x})=\sqrt{x^2+1} \hspace{20pt} &\text{Domain: } (-\infty,\infty) \hspace{10pt} &&\text{Range: } [1,\infty)
        \end{aligned}
        $
    \incrvariable\x
    \item%196
        $
        \begin{aligned}[t]
        \sinh(\tanh^{-1}{x})=\frac{x}{\sqrt{1-x^2}} \hspace{16.4pt} &\text{Domain: } (-1,1) \hspace{22pt} &&\text{Range: } (-\infty,\infty)
        \end{aligned}
        $
    \incrvariable\x
    \item%197
        $
        \begin{aligned}[t]
        \cosh(\tanh^{-1}{x})=\frac{1}{\sqrt{1-x^2}} \hspace{15.25pt} &\text{Domain: } (-1,1) \hspace{21.9pt} &&\text{Range: } [1,\infty)
        \end{aligned}
        $
    \incrvariable\x
    \item%198
        $
        \begin{aligned}[t]
        \tanh(\sinh^{-1}{x})=\frac{x}{\sqrt{1+x^2}} \hspace{16.72pt} &\text{Domain: } (-\infty,\infty) \hspace{9.5pt} &&\text{Range: } (-1,1)
        \end{aligned}
        $
    \incrvariable\x
    \item%199
        $
        \begin{aligned}[t]
        \tanh(\cosh^{-1}{x})=\frac{\sqrt{x^2-1}}{x} \hspace{15.48pt} &\text{Domain: } [1,\infty) \hspace{26.1pt} &&\text{Range: } [0,1)
        \end{aligned}
        $
    \end{enumerate}

The \hspace{} is the important (and annoying) part.

How can I improve my code without changing "enumerate" and "aligned" or something else that looks almost identical? (Something that keeps track of elapsed pts?)

OR with preamble here: (it's looonnng)

\documentclass[12pt, twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage{indentfirst}
\usepackage[left=1.2in,right=1.2in,top=1in,bottom=1in]{geometry}
\usepackage{titling}
\usepackage{titlesec}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.18, width=10cm}
\usepackage[fleqn]{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{newunicodechar}
\DeclareMathOperator{\sgn}{sgn}
\newunicodechar{ℤ}{\mathbb{Z}}
\newunicodechar{ℝ}{\mathbb{R}}
\usepackage{enumitem}
\usepackage{graphicx}
\setlength\mathindent{3cm}
\usepackage{etoolbox}
\usepackage{microtype}
\usepackage{array}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{romannum}
\usepackage{tocloft} %Change font size of TOC
%\renewcommand*{\arraystretch}{1.9}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\newcolumntype{C}{>{$\displaystyle}c<{$}}
\renewcommand{\contentsname}{Table of Content}
\DeclareMathOperator{\sech}{sech}
\DeclareMathOperator{\csch}{csch}
\usepgfplotslibrary{fillbetween}

\AtBeginDocument{\addtocontents{toc}{\small}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Odd page number on the right %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\align@preamble{% &\hfil \strut@ \setboxz@h{@lign$\m@th\displaystyle{##}$}% \ifmeasuring@\savefieldlength@\fi \llap{\set@field}% \tabskip\z@skip &\setboxz@h{@lign$\m@th\displaystyle{{}##}$}% \ifmeasuring@\savefieldlength@\fi \rlap{\set@field} \hfil \tabskip\alignsep@ }

\titleformat{\section} {\normalfont\huge\bfseries}{\makebox[45pt][l]{\thesection}}{0pt}{} \titleformat{\subsection} {\normalfont\large\bfseries}{\makebox[45pt][l]{\thesubsection}}{0pt}{} \titleformat{\subsubsection} {\normalfont\normalsize\bfseries}{\makebox[45pt][l]{\thesubsubsection}}{0pt}{}

\setlength{\droptitle}{-1em}

\setlength{\parindent}{45pt}

\title{\Huge{\textbf{Mathematics Directory}}} \author{\Large{Zhiyuan Liu}} \date{}

%\newcommand\X{0} %\renewcommand\X{0} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\newvariable#1{\gdef#1{0}} \def\addtovariable#1#2{\xdef#1{\number\numexpr#1+#2\relax}} \def\incrvariable#1{\addtovariable#1{1}}

\newvariable\x

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\maketitle

\section{} \subsection{Inverse Hyperbolic Trigonometric Identities} \raggedright\setlength{\parindent}{45pt} \begin{enumerate}[align=left,widest=a,labelindent=16mm,leftmargin=!] \incrvariable\x \setcounter{enumi}{\x} \item%194 $ \begin{aligned}[t] \sinh(\cosh^{-1}{x})=\sqrt{x^2-1} \hspace{20pt} &\text{Domain: } [1,\infty) \hspace{26.5pt} &&\text{Range: } [0,\infty) \end{aligned} $ \incrvariable\x \item%195 $ \begin{aligned}[t] \cosh(\sinh^{-1}{x})=\sqrt{x^2+1} \hspace{20pt} &\text{Domain: } (-\infty,\infty) \hspace{10pt} &&\text{Range: } [1,\infty) \end{aligned} $ \incrvariable\x \item%196 $ \begin{aligned}[t] \sinh(\tanh^{-1}{x})=\frac{x}{\sqrt{1-x^2}} \hspace{16.4pt} &\text{Domain: } (-1,1) \hspace{22pt} &&\text{Range: } (-\infty,\infty) \end{aligned} $ \incrvariable\x \item%197 $ \begin{aligned}[t] \cosh(\tanh^{-1}{x})=\frac{1}{\sqrt{1-x^2}} \hspace{15.25pt} &\text{Domain: } (-1,1) \hspace{21.9pt} &&\text{Range: } [1,\infty) \end{aligned} $ \incrvariable\x \item%198 $ \begin{aligned}[t] \tanh(\sinh^{-1}{x})=\frac{x}{\sqrt{1+x^2}} \hspace{16.72pt} &\text{Domain: } (-\infty,\infty) \hspace{9.5pt} &&\text{Range: } (-1,1) \end{aligned} $ \incrvariable\x \item%199 $ \begin{aligned}[t] \tanh(\cosh^{-1}{x})=\frac{\sqrt{x^2-1}}{x} \hspace{15.48pt} &\text{Domain: } [1,\infty) \hspace{26.1pt} &&\text{Range: } [0,1) \end{aligned} $ \end{enumerate} \end{document}

OR someone may have already answered it. Tell me the post. Cheers.

2 Answers2

6

I can think of two ways to accomplish your typesetting objective: with an alignat* environment, and with a longtable environment.

First, the alignat*-based approach. Observe: not a single \hspace statement anywhere in sight.

enter image description here

\documentclass[12pt, twoside]{article}
\usepackage[hmargin=1.2in,vmargin=1in]{geometry}

\usepackage{amsmath} \allowdisplaybreaks

\newcounter{mycount} \newcommand{\increment}{\refstepcounter{mycount}\themycount.}

\begin{document}

\setcounter{section}{4} % just for this example \stepcounter{subsection} \subsection{Inverse hyperbolic trigonometric identities}

\begin{alignat}{4} &&&&& \text{Domain} && \text{Range} \[\jot] % "header line" \increment &\qquad& \sinh(\cosh^{-1}{x}) &= \sqrt{x^2-1} &\qquad& [1,\infty) && [0,\infty) \ \increment && \cosh(\sinh^{-1}{x}) &= \sqrt{x^2+1} && (-\infty,\infty) &\qquad& [1,\infty) \ \increment && \sinh(\tanh^{-1}{x}) &= \frac{x}{\sqrt{1-x^2}} && (-1,1) && (-\infty,\infty) \[\jot] % "\jot" inserts a bit more vertical whitespace \increment && \cosh(\tanh^{-1}{x}) &= \frac{1}{\sqrt{1-x^2}} && (-1,1) && [1,\infty) \[\jot] \increment && \tanh(\sinh^{-1}{x}) &= \frac{x}{\sqrt{1+x^2}} && (-\infty,\infty) && (-1,1) \[\jot] \increment && \tanh(\cosh^{-1}{x}) &= \frac{\sqrt{x^2-1}}{x} && [1,\infty) && [0,1) \end{alignat} \end{document}


Second, the longtable-based approach. Observe: Still no \hspace directive anywhere in sight. :-)

enter image description here

\documentclass[12pt, twoside]{article}
\usepackage[hmargin=1.2in,vmargin=1in]{geometry}

\usepackage{amsmath} \allowdisplaybreaks

\usepackage{longtable,array,booktabs} \newcounter{mycount} \newcommand{\increment}{\refstepcounter{mycount}\arabic{mycount}.} \newcolumntype{L}{>{$\displaystyle}l<{$}} \newcolumntype{Z}{>{\refstepcounter{mycount}\arabic{mycount}.}l}

\begin{document}

\setcounter{section}{4} % just for this example \stepcounter{subsection} \subsection{Inverse hyperbolic trigonometric identities}

\begingroup \renewcommand\arraystretch{1.5} \addtolength\tabcolsep{5pt} \begin{longtable}{@{} Z LLLL @{}}

%% header \multicolumn{1}{@{}l}{} &&& \textup{Domain} & \textup{Range} \[1ex] \endhead

%% body of table & \sinh(\cosh^{-1}{x}) & \sqrt{x^2-1} & [1,\infty) & [0,\infty) \ & \cosh(\sinh^{-1}{x}) & \sqrt{x^2+1} & (-\infty,\infty) & [1,\infty) \ & \sinh(\tanh^{-1}{x}) & \frac{x}{\sqrt{1-x^2}} & (-1,1) & (-\infty,\infty) \ \addlinespace & \cosh(\tanh^{-1}{x}) & \frac{1}{\sqrt{1-x^2}} & (-1,1) & [1,\infty) \ \addlinespace & \tanh(\sinh^{-1}{x}) & \frac{x}{\sqrt{1+x^2}} & (-\infty,\infty) & (-1,1) \ \addlinespace & \tanh(\cosh^{-1}{x}) & \frac{\sqrt{x^2-1}}{x} & [1,\infty) & [0,1) \

\end{longtable} \endgroup \end{document}

Mico
  • 506,678
3

You have a set of tabulated data. A simple tabular would do. I'd enclose each math expression between separate delimiters \(...\). If you have a large data to present that exceed a page or you simply expect a page break somewhere between lines, you would need longtable instead.

The example below is based on longtable. Uncomment \everymath={\displaystyle} if all math expressions should be in display style. This may require additional vertical spacing via increased arraystretch or extrarowheight.

\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{longtable}

\begin{document} \section{Long table} \begingroup \newcounter{eqno}\setcounter{eqno}{190} \newcommand\addeqno{\stepcounter{eqno}\theeqno.} \setlength\extrarowheight{6pt} % \everymath={\displaystyle} %%% \begin{longtable}[r]{@{} r >{(}l<{)} >{Domain: (}l<{)} >{Range: (}l<{)} @{}} \addeqno & \sinh(\cosh^{-1}{x})=\sqrt{x^2-1} & [1,\infty) & [0,\infty) \ \addeqno & \cosh(\sinh^{-1}{x})=\sqrt{x^2+1} & (-\infty,\infty) & [1,\infty) \ \addeqno & \sinh(\tanh^{-1}{x})=\frac{x}{\sqrt{1-x^2}} & (-1,1) & (-\infty,\infty) \ \addeqno & \cosh(\tanh^{-1}{x})=\frac{1}{\sqrt{1-x^2}} & (-1,1) & [1,\infty) \ \addeqno & \tanh(\sinh^{-1}{x})=\frac{x}{\sqrt{1+x^2}} & (-\infty,\infty) & (-1,1) \ \addeqno & \tanh(\cosh^{-1}{x})=\frac{\sqrt{x^2-1}}{x} & [1,\infty) & [0,1) \end{longtable} \endgroup \end{document}

enter image description here


On the other hand, with enumerate, you would have to simulate columns. \makebox[<width>][<alignment>]{<content>} creates a box of a fixed width, no matter of the content. So if you place three such boxes horizontally, you achieve the desired effect. The downside is the width for each box has to be set manually and might need readjustment once you have changed the content. The package eqparbox provides a convenient macros, such as \eqmakebox[<label>][<alignment>}{<content>}. It works exactly as a regular makebox but instead of the width, user provides labels. Then, the width is calculated based on the longest content per label.

You can see this solution requires more coding, while the final effect is exactly the same as with longtable/tabular.

\documentclass{article}
\usepackage{enumitem}
\usepackage{eqparbox}
\usepackage{amsmath}

\begin{document} \section{Enumerate} \begin{enumerate}[ align=left, widest=a, labelindent=10mm, leftmargin=!, before={\setcounter{enumi}{190}}, ] \item \eqmakebox[eq][l]{(\sinh(\cosh^{-1}{x})=\sqrt{x^2-1})}% \quad \eqmakebox[do][l]{Domain:([1,\infty))}% \quad \eqmakebox[ra][l]{Range:([0,\infty))} \item \eqmakebox[eq][l]{(\cosh(\sinh^{-1}{x})=\sqrt{x^2+1})}% \quad \eqmakebox[do][l]{Domain: ((-\infty,\infty))}% \quad \eqmakebox[ra][l]{Range: ([1,\infty))} \item \eqmakebox[eq][l]{(\sinh(\tanh^{-1}{x}) = \frac{x}{\sqrt{1-x^2}})}% \quad \eqmakebox[do][l]{Domain: ((-1,1))}% \quad \eqmakebox[ra][l]{Range: ((-\infty,\infty))} \item \eqmakebox[eq][l]{(\cosh(\tanh^{-1}{x})=\frac{1}{\sqrt{1-x^2}})}% \quad \eqmakebox[do][l]{Domain: ((-1,1))}% \quad \eqmakebox[ra][l]{Range: ([1,\infty))} \item \eqmakebox[eq][l]{(\tanh(\sinh^{-1}{x})=\frac{x}{\sqrt{1+x^2}})}% \quad \eqmakebox[do][l]{Domain: ((-\infty,\infty))}% \quad \eqmakebox[ra][l]{Range: ((-1,1))} \item \eqmakebox[eq][l]{(\tanh(\cosh^{-1}{x})=\frac{\sqrt{x^2-1}}{x})}% \quad \eqmakebox[do][l]{Domain: ([1,\infty))}% \quad \eqmakebox[ra][l]{Range: ([0,1))} \end{enumerate} \end{document}

enter image description here

Celdor
  • 9,058
  • What does eq, do, ra mean? – Zhiyuan Liu Feb 08 '23 at 01:14
  • 1
    These are labels chosen by me. They just stand for equation, domain, and range--I should have used the full names for more clarity. Labels for this macro are like identifiers and groups texts for which boxes are calculated to tell \eqmakebox under which identifier the maximum text should be calculated for. Without it, all text would be considered. See the documentation. – Celdor Feb 08 '23 at 09:26
  • If you still have a problem, let me know and I'll edit the answer with an explanation. You may ask another question about it, as well. Just make sure to point out what is confusing and give a code, an example, which demonstrates difference between current and expected outcome. – Celdor Feb 08 '23 at 09:28
  • Thank you so much! Just wondering if there are any ways to manually set the length of the invisible "Box/Table" either a Long table or enumerate? Cheers. – Zhiyuan Liu Feb 08 '23 at 14:22
  • 1
    Well, I am guessing you might want to change gaps between "cells". In enumerate, substitute lines of \quad with \hspace{<<length>>}% (keep the % at the end); 1em = \quad, which is 10pt (see this answer. In longtable, add \setlength\tabcolsep{<<length>>} in code somewhere before \begin{longtable}; the default column sep. is 6pt. – Celdor Feb 08 '23 at 15:09
  • Oh my goodness it works so perfectly well! Thank you so much for making it easy. Now I can use it in different sections/subsections and it will look pretty! – Zhiyuan Liu Feb 09 '23 at 03:26