3

I want to use have numbering like equations for some regular text. So I am using equation environment. I am not writing any mathematics in it, so I'll also use textrm.

This is my basic code -

\documentclass[fleqn]{article}
\setlength{\mathindent}{0pt}

\begin{document}
\noindent Select an\\
Select apple\\
\begin{equation}
\textrm{Merge an \& apple.}
\end{equation}
\end{document}

If I am not wrong the equation comes as a new paragraph as it has an indent and it also leaves some space in between. (Please correct me if I'm wrong.) Basically I don't want this paragraph & I want this change globally. I've already removed the indent by modifying the mathindent Is there any way to change something like mathpar?


Screenshot of the desired output - (but with the equation number) 1


Code with the help of the solution provided by leandriis -

\documentclass[fleqn]{article}
\usepackage{amsmath}
\setlength{\mathindent}{0pt}
\newcounter{mynumber}
\newcommand{\myno}[1]{\refstepcounter{mynumber}(\arabic{mynumber})\label{#1}}

\begin{document}
\noindent Select an\\
Select apple\\
Merge an \& apple. \myno{first}\\

Now merge \eqref{first}
\end{document}

This code produced -

2

Niranjan
  • 3,435

2 Answers2

5

Probably you could use something like the following:

enter image description here

The blue lines indicate the text width. The red box around the reference is caused by hyperref.

\documentclass[fleqn]{article}

\usepackage{tabularx}
\usepackage{hyperref}
\setlength{\parindent}{0pt}

\newcounter{mynumber}
\newcommand{\myno}[1]{\refstepcounter{mynumber}(\arabic{mynumber})\label{#1}}

\begin{document}

\begin{tabularx}{\textwidth}{@{}Xr@{}}
Select an \\
Select apple \\
Merge an \& apple. & \myno{label}\\
\end{tabularx}

Here comes a reference: \ref{label}

\end{document}
leandriis
  • 62,593
  • Yes this is a good solution for me. Actually the tabular package is not needed for my purpose, but your definitions helped me. Thank you so much. – Niranjan Oct 03 '19 at 14:07
  • Hey! I am sorry, I said this worked for me, but I want the number to come on the extreme right of the page as it comes in the equation environment. Please tell me how to do it. – Niranjan Oct 03 '19 at 14:38
  • @Niranjan: As you can see from my screenshot, the numbers are in fact already at the right margin. This is due to me using tabularx. If you insist on not using a table, you probably can use something like Merge an \& apple. \hfill \myno{label} instead. – leandriis Oct 03 '19 at 15:28
  • Oh yes. Thanks! – Niranjan Oct 03 '19 at 15:41
  • I just added hfill to the command suggested by you like this. \newcommand{\myno}[1]{\hfill\refstepcounter{mynumber}(\arabic{mynumber})\label{#1}} & it produced what I wanted globally :) – Niranjan Oct 04 '19 at 13:24
5

I guess you want something like this:

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum} % for context

\begin{document}

\lipsum[1][1-3]
\begin{flalign}
\begin{tabular}{@{}l@{}}
Select an\\
Select apple\\
Merge an \& apple.
\end{tabular}&&\label{whatever}
\end{flalign}
\lipsum*[2][1-3]

Reference to the thing above is \ref{whatever}.

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks, but this is probably not what I want, because I also want to refer them. Answer provided by @leandriis works fine for me. – Niranjan Oct 03 '19 at 14:08
  • @Niranjan You just add \label{whatever} outside the tabular and use \ref{whatever}. I added it. – egreg Oct 03 '19 at 14:12
  • Yes please see the edit. I've changed the question as I just realized equation was not a right choice. – Niranjan Oct 03 '19 at 14:16