LaTeX forum ⇒ GeneralReference to custom Counter depending on Heading Number

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

Reference to custom Counter depending on Heading Number

Postby LavaTyper » Tue Jan 29, 2013 2:31 am

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:

  1. \documentclass[11pt]{article}
  2.  
  3. % Number activities and reset them with each subsection
  4. \newcounter{Activity}\setcounter{Activity}{0}
  5. \makeatletter
  6. \@addtoreset{Activity}{subsection}
  7. \makeatother
  8. \def\Activity{\thesubsection.\arabic{Activity}}
  9. \def\ActivityText{\\ \addtocounter{Activity}{1}\textbf{Activity \Activity:}}
  10.  
  11.  
  12.  
  13. % THE DOCUMENT
  14.  
  15. \begin{document}
  16.  
  17. \section{My first section}
  18.  
  19. \subsection{My first subsection}
  20.  
  21. \textbf{\ActivityText} Some activity text
  22.  
  23. \textbf{\ActivityText} Another activity text
  24.  
  25. \textbf{\ActivityText} How do I cite ``Activity 1.1.2"? What code do I need?
  26.  
  27. \subsection{My second subsection}
  28.  
  29. \textbf{\ActivityText} This should be Activity 1.2.1. How do I cite Activity 1.1.1 for comparison?
  30.  
  31.  
  32. \end{document}

Tags:

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Tue Jan 29, 2013 11:13 am

Set up your activities with a theorem-like environment, perhaps customized by the ntheorem package.
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{ntheorem}
  4.  
  5. \theorembodyfont{\normalfont}
  6. \theoremseparator{:}
  7. \newtheorem{activity}{Activity}[subsection]
  8.  
  9. \begin{document}
  10. \section{My first section}
  11. \subsection{My first subsection}
  12.  
  13. \begin{activity}\label{act:some}
  14. Some activity text.
  15. \end{activity}
  16.  
  17. \begin{activity}\label{act:another}
  18. Another activity text.
  19. \end{activity}
  20.  
  21. \begin{activity}
  22. Citation of activity \ref{act:another}.
  23. \end{activity}
  24.  
  25. \subsection{My second subsection}
  26.  
  27. \begin{activity}\label{act:should}
  28. This should be Activity \ref{act:should}. This is the way to cite Activity \ref{act:some}.
  29. \end{activity}
  30. \end{document}

An alternative would be to use amsthm.


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am

Postby LavaTyper » Tue Jan 29, 2013 4:23 pm

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: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Wed Jan 30, 2013 10:28 am

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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am

Postby LavaTyper » Wed Jan 30, 2013 5:01 pm

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.

  1. \documentclass[12pt]{article}
  2. \usepackage{graphicx}
  3. \usepackage{wrapfig}
  4. \usepackage{parskip}
  5. \usepackage{ntheorem}
  6.  
  7.  
  8. % UNDERLINES - I want to separate
  9.  
  10. \makeatletter
  11. \def\vhrulefill#1{\leavevmode\leaders\hrule\@height#1\hfill \kern\z@}
  12. \makeatother
  13.  
  14. \def\underlinethickness{1pt}
  15. \def\underlinefill{\vhrulefill{\underlinethickness}}
  16.  
  17.  
  18. \theorembodyfont{\normalfont}
  19. \theoremseparator{:}
  20. \newtheorem{activity}{Activity}[subsection]
  21. \newtheorem{workedexample}{Worked Example}[subsection]
  22.  
  23.  
  24. \parskip=0pt
  25. \parindent=0.5in
  26.  
  27.  
  28.  
  29.  
  30. % THE DOCUMENT
  31.  
  32. \begin{document}
  33.  
  34.  
  35. \section{First section}
  36.  
  37. \subsection{First subsection}
  38.  
  39. \begin{enumerate}
  40. \item Here is a list of properties.
  41. \item I do not want a blank line between
  42. \item items in my list.
  43. \end{enumerate}
  44. \vspace{\baselineskip}
  45.  
  46. Here is some informative text for the subsection. Here is some informative text for the subsection.
  47.  
  48. Here is a second paragraph. I do not want empty space between these two paragraphs.
  49.  
  50. {\noindent}\underlinefill{\noindent}
  51.  
  52. \begin{wrapfigure}{r}{0.15\textwidth}
  53. \caption{\label{figure:flipxyLb}Caption}
  54. \includegraphics[width=0.15\textwidth]{flipxyLb}
  55. \end{wrapfigure}
  56.  
  57. \begin{activity}\label{activity:firsttriangle}
  58. I want to wrap Figure \ref{figure:flipxyLb} to the right of the Activities.
  59. \end{activity}
  60.  
  61. \begin{activity}\label{activity:secondtriangle}
  62. 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?
  63. \end{activity}
  64.  
  65. \begin{activity}
  66. 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.
  67.  
  68. As an additional exercise, show that
  69. \begin{equation}
  70. \label{equation:trianglexyL}
  71. \sin \beta = \frac{x}{L}, \quad \cos \beta = \frac{y}{L}, \quad \tan \beta = \frac{x}{y}.
  72. \end{equation}
  73. 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$."
  74. \end{activity}
  75.  
  76. {\noindent}\underlinefill{\noindent}
  77.  
  78. \end{document}
Attachments
flipxyLb.pdf
(13.56 KiB) Downloaded 166 times

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Wed Jan 30, 2013 10:16 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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am

Postby LavaTyper » Thu Jan 31, 2013 9:33 pm

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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 17 guests