2

i wanna number the lines that i choose. And the number should be outside of pdf text zone. And the numbering symbol is (1), (2) not 1,2.

I use miktex, texniccenter. and XElatex -> pdf I wanna do like this. could u tell me the code? help me please~~~

enter image description here

5
  • 3
    Welcome! In your example the numbers are on examples (probably a kind of theorem environment) and equations, not on "whatever lines you want", and they are numbered with the same counter. Is that what you want or is a generic command to "number this line"? Must the numbering be shared with equations, theorems and so on? Please specify better your question.
    – Rmano
    Commented Sep 11, 2019 at 5:48
  • hi! thank u for u r comment. I want "number my example(that i want or is selected), theorem(that i want or is selected), definition(that i want or is selected), example(that i want or is selected) , equation(that i want or is selected) and so on... if it is more easy to code only examples and equations, i want it. but generic command is also good! i'm not good at english. there is limit to my expression. sorry.
    – hohohaha
    Commented Sep 11, 2019 at 12:11
  • and the box code is \begin{mdframed}[backgroundcolor = gray!20] \end{mdframed} ........... i also need numbering outside of the box .. please help me:)
    – hohohaha
    Commented Sep 11, 2019 at 12:27
  • Hi, ok --- if you could post a minimal working example (MWE) showing what you have, it will be much easier for people here to try to solve your problem.
    – Rmano
    Commented Sep 11, 2019 at 13:17
  • See also tex.stackexchange.com/questions/303243/…
    – Rmano
    Commented Sep 11, 2019 at 13:21

1 Answer 1

2

Ok, this is not trivial... I have found a solution thanks to @GuM, @David Carlisle, and looking at the code of amsthm.sty.

Caveats:

  1. It is touching several internal macros. Can explode with upgrades;
  2. It needs leqno, no idea on how to adapt it for two-sided documents (solutions welcome);
  3. If you move the mdframed thing with a different innerleftmargin or leftmargin the number lose it's alignement.
\documentclass[leqno]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{amsmath, amsthm}
\usepackage{mdframed}
%% Code by David Carlisle at https://tex.stackexchange.com/a/258575/38080
\makeatletter
\def\formatout#1{\hbox{\hskip1sp\m@th\llap{%
    \normalcolor\normalfont#1\hspace{1.0cm}}}}
\let\oldmaketag@@@\maketag@@@
\def\oldtagform@#1{\oldmaketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\oldtagform@{\ref{#1}}}}
\def\maketag@@@#1{\formatout{#1}}
%
% redefine the amsthm theorem start macro to use \formatout
%
\def\@begintheorem#1#2[#3]{%
  \deferred@thm@head{\the\thm@headfont \thm@indent
    \@ifempty{#1}{\let\thmname\@gobble}{\let\thmname\@iden}%
    \@ifempty{#2}{\let\thmnumber\@gobble}{\let\thmnumber\thmnumber}%
    \@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
    \thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
    \the\thm@headpunct
    \thmheadnl % possibly a newline.
    \hskip\thm@headsep
  }%
  \ignorespaces}%
\makeatother
\swapnumbers
\def\thmnumber#1{\formatout{(#1)}}
% https://tex.stackexchange.com/a/303245/38080
\newtheorem{thm}[equation]{Theorem}
\newtheorem{exa}[equation]{Example}
\begin{document}

Let's start with
\begin{equation}
    E=mc^2
    \label{eq:mc2}
\end{equation}
so we go to:

\begin{thm}{Einsteins:}
    $E$ is equal to $m$ $c$ squared
    \label{thE}
\end{thm}

This leads to this

\begin{exa}{Example:}
    $E$ is equal to $m$ multiplied a BIG number
    \label{exE}
\end{exa}

% innerleftmargin+leftmargin must be 0pt...
\begin{mdframed}[backgroundcolor=gray!20, innerleftmargin=0pt, linewidth=0pt]
Also
\begin{equation}
    m=E/c^2
    \label{eq:mc2i}
\end{equation}
\end{mdframed}

And the references are Eq.~\ref{eq:mc2}, Th.~\ref{thE}, Ex.~\ref{exE}.

\end{document}

Which results in:

enter image description here

4
  • 1
    wow!!!!!!very very very very very very very thank u!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :)
    – hohohaha
    Commented Sep 12, 2019 at 11:38
  • sorry.. i have a problem.. how can i reset the number???
    – hohohaha
    Commented Sep 12, 2019 at 12:09
  • thank u i solve it!
    – hohohaha
    Commented Sep 12, 2019 at 13:44
  • If the answer solves your problem, please consider accepting it: tex.stackexchange.com/help/someone-answers
    – Rmano
    Commented Sep 12, 2019 at 15:36

You must log in to answer this question.

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