GeneralReference to custom Counter depending on Heading Number

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

Reference to custom Counter depending on Heading Number

Post by LavaTyper »

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:

Code: Select all

\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}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Reference to custom Counter depending on Heading Number

Post by localghost »

Set up your activities with a theorem-like environment, perhaps customized by the ntheorem package.

Code: Select all

\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
LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am

Reference to custom Counter depending on Heading Number

Post by LavaTyper »

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.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Reference to custom Counter depending on Heading Number

Post by localghost »

Please prepare a proper minimal example to give an adequate problem description. For example it is completely unclear which spacing you mean.
LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am

Reference to custom Counter depending on Heading Number

Post by LavaTyper »

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.

Code: Select all

\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
(13.56 KiB) Downloaded 477 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Reference to custom Counter depending on Heading Number

Post by localghost »

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).
LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am

Reference to custom Counter depending on Heading Number

Post by LavaTyper »

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.
Post Reply