## LaTeX forum ⇒ General ⇒ Reference to custom Counter depending on Heading Number

LaTeX specific issues not fitting into one of the other forums of this category.
LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am

### Reference to custom Counter depending on Heading Number

Greetings again!

I am using LaTeX to write activities for a science class, and each activity comes with a preamble like Activity 1.2.1 for the first activity of Section 1.2.

The problem, however, is that I am not sure how to cite a particular activity later in the document.

Here is an example explaining my case:

\documentclass[11pt]{article} % Number activities and reset them with each subsection\newcounter{Activity}\setcounter{Activity}{0}\makeatletter\@addtoreset{Activity}{subsection}\makeatother\def\Activity{\thesubsection.\arabic{Activity}}\def\ActivityText{\\ \addtocounter{Activity}{1}\textbf{Activity \Activity:}}   % THE DOCUMENT \begin{document} \section{My first section} \subsection{My first subsection} \textbf{\ActivityText} Some activity text \textbf{\ActivityText} Another activity text \textbf{\ActivityText} How do I cite Activity 1.1.2"? What code do I need? \subsection{My second subsection} \textbf{\ActivityText} This should be Activity 1.2.1. How do I cite Activity 1.1.1 for comparison?  \end{document}

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
Set up your activities with a theorem-like environment, perhaps customized by the ntheorem package.
\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage{ntheorem} \theorembodyfont{\normalfont}\theoremseparator{:}\newtheorem{activity}{Activity}[subsection] \begin{document}   \section{My first section}     \subsection{My first subsection}        \begin{activity}\label{act:some}         Some activity text.       \end{activity}        \begin{activity}\label{act:another}         Another activity text.       \end{activity}        \begin{activity}         Citation of activity \ref{act:another}.       \end{activity}      \subsection{My second subsection}        \begin{activity}\label{act:should}         This should be Activity \ref{act:should}. This is the way to cite Activity \ref{act:some}.       \end{activity}\end{document}

An alternative would be to use amsthm.

Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am
Alright, but there's a conflict with when I use parskip and set the spacing to 0pt.

I want each activity spaced by \baselineskip how can I do this?

-
Also, something custom:

Within a particular subsection, how can I wrap a horizontal line around the top and bottom of a group of activities?
Last edited by localghost on Wed Jan 30, 2013 10:28 am, edited 2 times in total.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
Please prepare a proper minimal example to give an adequate problem description. For example it is completely unclear which spacing you mean.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am
I already did that in my first post. I formatted it and described the problem I'm having, I couldn't have possibly minimized it any more than that. Why are you attacking me for something that I already did?

And I thought that my spacing issue was perfectly clear. "I want each activity spaced by baselineskip ":

each activity (meaning, each theorem environment representing the activities as illustrated in Post #2 of this thread)
spaced by \baselineskip (meaning, I want a space of the value \baselineskip, which is whatever the value \baselineskip is, between two subsequent activities).

Oh by the way:
When I used ntheorem, it introduced other problems with my wrapped figures.

When I used your ntheorem environment, it caused all my wrapped figures, which were originally in the activities, to appear in completely wrong places on the page. See below for an example using wrapfig.

Finally, the parskip package introduces problems where if I turn it off, both Activities and enumerated items are no longer spaced apart. I just want the Activities to be spaced, but not enumerated items, but parskip won't let me do that.

\documentclass[12pt]{article}\usepackage{graphicx}\usepackage{wrapfig}\usepackage{parskip}\usepackage{ntheorem}  % UNDERLINES - I want to separate \makeatletter   \def\vhrulefill#1{\leavevmode\leaders\hrule\@height#1\hfill \kern\z@}\makeatother \def\underlinethickness{1pt}\def\underlinefill{\vhrulefill{\underlinethickness}}  \theorembodyfont{\normalfont}\theoremseparator{:}\newtheorem{activity}{Activity}[subsection]\newtheorem{workedexample}{Worked Example}[subsection]  \parskip=0pt\parindent=0.5in    % THE DOCUMENT \begin{document}  \section{First section} \subsection{First subsection} \begin{enumerate}\item Here is a list of properties.\item I do not want a blank line between\item items in my list.\end{enumerate}\vspace{\baselineskip} Here is some informative text for the subsection. Here is some informative text for the subsection.  Here is a second paragraph. I do not want empty space between these two paragraphs. {\noindent}\underlinefill{\noindent} \begin{wrapfigure}{r}{0.15\textwidth}\caption{\label{figure:flipxyLb}Caption}\includegraphics[width=0.15\textwidth]{flipxyLb}\end{wrapfigure} \begin{activity}\label{activity:firsttriangle}I want to wrap Figure \ref{figure:flipxyLb} to the right of the Activities.\end{activity} \begin{activity}\label{activity:secondtriangle}I want a blank space between Activity \ref{activity:firsttriangle} and Activity \ref{activity:secondtriangle}. Currently there is none. But if I turn off \verb2\usepackage{parskip}2 then I get the space between activities, but then there is a space between items in enumerate, and I don't want that. Why does it do that?\end{activity} \begin{activity}The triangle in Figure \ref{figure:flipxyLb} appears in the wrong place. I want it to appear in the space containing this group of Activities. As an additional exercise, show that\begin{equation}\label{equation:trianglexyL}\sin \beta = \frac{x}{L}, \quad \cos \beta = \frac{y}{L}, \quad \tan \beta = \frac{x}{y}.\end{equation}Explain why the cosine of an angle is not always $x$ over $L$" and why the sine of an angle is not always $y$ over $L$."\end{activity} {\noindent}\underlinefill{\noindent} \end{document}
Attachments
flipxyLb.pdf

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
With all your subsequent additions things are becoming more complicated and at the moment I don't have the time for a thorough review. My approach was only an idea for more convenience in declaring such structures.

So I suggest to roll back to your original activity definition and replace \addtocounter by \refstepcounter and use \ref for corresponding cross-references. In this context you should take a look at the optional argument of \newcounter. For application of the commands please follow the links (click on the commands).
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am
How do I do that?

I am confused. The directions say:

"The \refstepcounter command works in the same way as \stepcounter. See \stepcounter, except it also defines the current \ref value to be the result of \thecounter."

Where exactly am I supposed to place the \ref?
I tried searching all over the internet for an example of how it is used and I couldn't find anything relevant.