Spacing between groups of two list items
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I'm trying to format a homework document, in which I want to write the questions and answers in a list. The question is followed by an answer, after which I want a slightly bigger gap before the next question and answer
beginitemize
item[Q.] Question 1
item[A.] Answer 1
%space here
item[Q.] Question 2
item[A.] Answer 2
enditemize
Currently, I'm adding a space by using an empty list item (item
). The output is shown below. Unfortunately, this creates a much larger space than I want. Is there a cleaner way to do this?
formatting lists
add a comment |Â
up vote
5
down vote
favorite
I'm trying to format a homework document, in which I want to write the questions and answers in a list. The question is followed by an answer, after which I want a slightly bigger gap before the next question and answer
beginitemize
item[Q.] Question 1
item[A.] Answer 1
%space here
item[Q.] Question 2
item[A.] Answer 2
enditemize
Currently, I'm adding a space by using an empty list item (item
). The output is shown below. Unfortunately, this creates a much larger space than I want. Is there a cleaner way to do this?
formatting lists
Welcome to TeX.SX! A hackish way would be to insertvspace<some amount>
there. For example,vspace0.25cm
. This would be quite boring for longer lists though...
â Phelype Oleinik
Sep 10 at 22:48
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I'm trying to format a homework document, in which I want to write the questions and answers in a list. The question is followed by an answer, after which I want a slightly bigger gap before the next question and answer
beginitemize
item[Q.] Question 1
item[A.] Answer 1
%space here
item[Q.] Question 2
item[A.] Answer 2
enditemize
Currently, I'm adding a space by using an empty list item (item
). The output is shown below. Unfortunately, this creates a much larger space than I want. Is there a cleaner way to do this?
formatting lists
I'm trying to format a homework document, in which I want to write the questions and answers in a list. The question is followed by an answer, after which I want a slightly bigger gap before the next question and answer
beginitemize
item[Q.] Question 1
item[A.] Answer 1
%space here
item[Q.] Question 2
item[A.] Answer 2
enditemize
Currently, I'm adding a space by using an empty list item (item
). The output is shown below. Unfortunately, this creates a much larger space than I want. Is there a cleaner way to do this?
formatting lists
formatting lists
asked Sep 10 at 22:44
Abhijeet Krishnan
262
262
Welcome to TeX.SX! A hackish way would be to insertvspace<some amount>
there. For example,vspace0.25cm
. This would be quite boring for longer lists though...
â Phelype Oleinik
Sep 10 at 22:48
add a comment |Â
Welcome to TeX.SX! A hackish way would be to insertvspace<some amount>
there. For example,vspace0.25cm
. This would be quite boring for longer lists though...
â Phelype Oleinik
Sep 10 at 22:48
Welcome to TeX.SX! A hackish way would be to insert
vspace<some amount>
there. For example, vspace0.25cm
. This would be quite boring for longer lists though...â Phelype Oleinik
Sep 10 at 22:48
Welcome to TeX.SX! A hackish way would be to insert
vspace<some amount>
there. For example, vspace0.25cm
. This would be quite boring for longer lists though...â Phelype Oleinik
Sep 10 at 22:48
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
5
down vote
Very basic solution which doesn't require manual spacing:
Define two macros, question
and answer
, which do item[Q.]
and item[A.]
, respectively. The question
macro also inserts a vertical space of 0.25 cm
if it's not in the first question, so the space between the list and the paragraph is right.
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.]
defanswer%
item[A.]
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question Question 1
answer Answer 1
question Question 2
answer Answer 2
question Question 2
answer Answer 2
question Question 2
answer Answer 2
enditemize
lipsum[1]
enddocument
and, following A. Ellet's suggestion, if you will always label each item with "Question /Answer ", you can use a counter:
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newcounterQuestionCounter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
setcounterQuestionCounter1% Remove this to have the same numbering across different itemize's
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.] Question theQuestionCounter:space
defanswer%
item[A.] Answer theQuestionCounter:space
stepcounterQuestionCounter
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question What's your name?
answer Foo
question Where do you live?
answer Bar
question How old are you?
answer -1
enditemize
lipsum[1]
enddocument
I would incorporate a counter,paircounter
for each question/answer pair so thatquestion
expands toitem[Q.] Question thepaircounter
andanswer
expands toitem[A.] Answer thepaircounter
.
â A.Ellett
Sep 10 at 23:13
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
add a comment |Â
up vote
3
down vote
You have several options.
- The simplest is: Define your own command, say
questionVSpace
, to use a space between elements within a list. Observe that the definition of vertical space command may depend on the class you use. - There are more elaborate ways to do it. I recommend using a command for doing so. This command should handle the vertical space automatically and should handle layout issues globally, e.g. if you want to change "Q." to "Question". A crude but more useful way is my second variant. This also allows to enumerate the question, see my code below.
These variants are implemented in the following MWE.
documentclassarticle
%you can manually choose a space here if you do not like the predefined ones
%In case you want to use one of the predfined ones, say smallskip, you should still use questionVSpace and replace vspace9ex with smallskip
newcommandquestionVSpacevspace9ex
newcounterquestionCounter
newcommandqAndA[2]
%The following code automatically adds the space unless it is the first question.
ifnumvaluequestionCounter>0
bigskip%you can choose a different space here.
fi
stepcounterquestionCounter
% You could also change "Q." to "Q. thequestionCounter"
item[Q.] #1
item[A.] #2
begindocument
sectionVariant A
Test
beginitemize
item[Q.] Question 1
item[A.] Answer 1
smallskip
item[Q.] Question 2
item[A.] Answer 2
medskip
item[Q.] Question 3
item[A.] Answer 3
bigskip
item[Q.] Question 4
item[A.] Answer 4
questionVSpace
item[Q.] Question 5
item[A.] Answer 5
enditemize
sectionVariant B
Test
beginitemize
qAndA Text fooText bar
qAndA Text fooText bar
qAndA Text fooText bar
enditemize
enddocument
1
I think you forgot something atifthequestionCounter
. This will always evaluate to false. See the extra vertical space between0.2 B
andQ. Text foo
.
â Phelype Oleinik
Sep 10 at 23:14
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
add a comment |Â
up vote
2
down vote
More simply, you could use a different itemize for each Q & A:
beginitemize
item[Q.] Question 1
item[A.] Answer 1
end[itemize}
beginitemize
item[Q.] Question 2
item[A.] Answer 2
enditemize
add a comment |Â
up vote
1
down vote
Here's an approach using a new environment called QA
. I've tried to throw in enough to let you see what's possible beyond just what you asked and to allow you to see where additional tweaks might enhance what you're doing. I've exaggerated the effect of adding vertical space between an answer and a following question: tweak to something more suitable.
documentclassarticle
newcounteraeQAcounter
newcounteraePAIRcounter
defaeRememberLastPair1
newenvironmentQA[1]
%% save the definition of `item` so I can access
%% its definition later when I *redefine* it.
letaeitemitem
%% a crude key value'ish approach to remembering
%% previous value for question/answer pair.
defaeTestA#1%%
defaeTestBremember previous%%
ifxaeTestAaeTestB
%% nothing to do here!!
else
defaeRememberLastPair1%%
fi
setcounteraePAIRcounteraeRememberLastPair%%
beginlist%%
sffamily
ifoddtheaeQAcounter Question theaePAIRcounter%%
else
Answer theaePAIRcounter%%
stepcounteraePAIRcounter%%
fi
:%%
usecounteraeQAcounter%%
defitem%%
%% only add space if not the first question
ifnumtheaePAIRcounter=aeRememberLastPair
%% do nothing!!!!
else
%% only add space before question and after
%% an answer (the even `item` in the list)
ifoddtheaeQAcounter
else
vspace4ex%%
fi
fi
aeitem
letquestionitem
letansweritem
xdefaeRememberLastPairtheaePAIRcounter%%
endlist
begindocument
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida mauris. Nam arcu
beginQA
question What do you say when you part from someone?
question bye
question What is a fruit that shouldn't be mixed with apples?
answer An orange.
endQA
Nam dui ligula, fringilla a, euismod sodales, sollicitudin
vel, wisi. Morbi auctor lorem non justo. Nam lacus libero,
pretium at, lobortis vitae, ultricies et.
textbfsffamily And, we continue with more questions:
beginQA[remember previous]
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
textbfsffamily And, Here is a new set of questions:
beginQA
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
enddocument
Notice that I use two counters here. One counter is essentially the list's counter for each item. If it's odd, that means I'm asking a question. If it's even, that means I'm answering a question. The second counter is only advanced once the question/answer pair has been established.
Also, notice that question
and answer
are stupid, in the sense that they're really just stand-ins for item
and don't do much else. Everything is handled through item
and tracking counters. I try to let the environment itself handle the tracking of questions and answers. The only difficulty comes when adding space. From within the list
environment's arguments, not much can be done.
One thing to note, you cannot insert vspace...
from within the first argument to the list
environment. It will do nothing there and just be ignored for the most part (or show up where you don't expect it).
add a comment |Â
up vote
1
down vote
The space between items is controlled by itemsep
, so you can fix for each item, with the advantage that your Q & A lists will not influenced by the default itemsep
as it would happen using some additional vertical space as vspace
,bigskip
. I will add some glue too, not a fixed length, that would help to avoid orphan items/lines.
This can be done easily as already proposed making a macro for each item type, and I think that semantically is better that a complex redefine of item
type to hiddenly switch from "Q." to "A.". With the "keep it simple" principle in mind, I do not see the need of conditionals or counters (I will edit the answer if you clarify this point), so the macros could be some like this:
documentclassarticle
newcommandQ[1]item[bfseries Q.]
itemsep2pt plus 2pt #1
newcommandA[1]item[bfseries A.]
itemsep1em plus .2em minus .1em #1
newenvironmentq-asection*Questions
and answersbeginitemizeenditemize
begindocument
beginq-a
Q Question 1
A Answer 1
Q Question 2
A Answer 2
Q Question 3
A Answer 3
endq-a
enddocument
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Very basic solution which doesn't require manual spacing:
Define two macros, question
and answer
, which do item[Q.]
and item[A.]
, respectively. The question
macro also inserts a vertical space of 0.25 cm
if it's not in the first question, so the space between the list and the paragraph is right.
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.]
defanswer%
item[A.]
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question Question 1
answer Answer 1
question Question 2
answer Answer 2
question Question 2
answer Answer 2
question Question 2
answer Answer 2
enditemize
lipsum[1]
enddocument
and, following A. Ellet's suggestion, if you will always label each item with "Question /Answer ", you can use a counter:
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newcounterQuestionCounter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
setcounterQuestionCounter1% Remove this to have the same numbering across different itemize's
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.] Question theQuestionCounter:space
defanswer%
item[A.] Answer theQuestionCounter:space
stepcounterQuestionCounter
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question What's your name?
answer Foo
question Where do you live?
answer Bar
question How old are you?
answer -1
enditemize
lipsum[1]
enddocument
I would incorporate a counter,paircounter
for each question/answer pair so thatquestion
expands toitem[Q.] Question thepaircounter
andanswer
expands toitem[A.] Answer thepaircounter
.
â A.Ellett
Sep 10 at 23:13
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
add a comment |Â
up vote
5
down vote
Very basic solution which doesn't require manual spacing:
Define two macros, question
and answer
, which do item[Q.]
and item[A.]
, respectively. The question
macro also inserts a vertical space of 0.25 cm
if it's not in the first question, so the space between the list and the paragraph is right.
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.]
defanswer%
item[A.]
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question Question 1
answer Answer 1
question Question 2
answer Answer 2
question Question 2
answer Answer 2
question Question 2
answer Answer 2
enditemize
lipsum[1]
enddocument
and, following A. Ellet's suggestion, if you will always label each item with "Question /Answer ", you can use a counter:
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newcounterQuestionCounter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
setcounterQuestionCounter1% Remove this to have the same numbering across different itemize's
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.] Question theQuestionCounter:space
defanswer%
item[A.] Answer theQuestionCounter:space
stepcounterQuestionCounter
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question What's your name?
answer Foo
question Where do you live?
answer Bar
question How old are you?
answer -1
enditemize
lipsum[1]
enddocument
I would incorporate a counter,paircounter
for each question/answer pair so thatquestion
expands toitem[Q.] Question thepaircounter
andanswer
expands toitem[A.] Answer thepaircounter
.
â A.Ellett
Sep 10 at 23:13
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Very basic solution which doesn't require manual spacing:
Define two macros, question
and answer
, which do item[Q.]
and item[A.]
, respectively. The question
macro also inserts a vertical space of 0.25 cm
if it's not in the first question, so the space between the list and the paragraph is right.
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.]
defanswer%
item[A.]
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question Question 1
answer Answer 1
question Question 2
answer Answer 2
question Question 2
answer Answer 2
question Question 2
answer Answer 2
enditemize
lipsum[1]
enddocument
and, following A. Ellet's suggestion, if you will always label each item with "Question /Answer ", you can use a counter:
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newcounterQuestionCounter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
setcounterQuestionCounter1% Remove this to have the same numbering across different itemize's
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.] Question theQuestionCounter:space
defanswer%
item[A.] Answer theQuestionCounter:space
stepcounterQuestionCounter
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question What's your name?
answer Foo
question Where do you live?
answer Bar
question How old are you?
answer -1
enditemize
lipsum[1]
enddocument
Very basic solution which doesn't require manual spacing:
Define two macros, question
and answer
, which do item[Q.]
and item[A.]
, respectively. The question
macro also inserts a vertical space of 0.25 cm
if it's not in the first question, so the space between the list and the paragraph is right.
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.]
defanswer%
item[A.]
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question Question 1
answer Answer 1
question Question 2
answer Answer 2
question Question 2
answer Answer 2
question Question 2
answer Answer 2
enditemize
lipsum[1]
enddocument
and, following A. Ellet's suggestion, if you will always label each item with "Question /Answer ", you can use a counter:
documentclassarticle
usepackagelipsum% Just for dummy text
makeatletter
newcounterQuestionCounter
newififfirstquestion
firstquestiontrue
defquestion%
iffirstquestion
setcounterQuestionCounter1% Remove this to have the same numbering across different itemize's
firstquestionfalse
else
vspace0.25cm%
fi
item[Q.] Question theQuestionCounter:space
defanswer%
item[A.] Answer theQuestionCounter:space
stepcounterQuestionCounter
makeatother
begindocument
pagenumberinggobble
lipsum[1]
beginitemize
question What's your name?
answer Foo
question Where do you live?
answer Bar
question How old are you?
answer -1
enditemize
lipsum[1]
enddocument
edited Sep 10 at 23:21
answered Sep 10 at 22:56
Phelype Oleinik
17.3k43770
17.3k43770
I would incorporate a counter,paircounter
for each question/answer pair so thatquestion
expands toitem[Q.] Question thepaircounter
andanswer
expands toitem[A.] Answer thepaircounter
.
â A.Ellett
Sep 10 at 23:13
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
add a comment |Â
I would incorporate a counter,paircounter
for each question/answer pair so thatquestion
expands toitem[Q.] Question thepaircounter
andanswer
expands toitem[A.] Answer thepaircounter
.
â A.Ellett
Sep 10 at 23:13
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
I would incorporate a counter,
paircounter
for each question/answer pair so that question
expands to item[Q.] Question thepaircounter
and answer
expands to item[A.] Answer thepaircounter
.â A.Ellett
Sep 10 at 23:13
I would incorporate a counter,
paircounter
for each question/answer pair so that question
expands to item[Q.] Question thepaircounter
and answer
expands to item[A.] Answer thepaircounter
.â A.Ellett
Sep 10 at 23:13
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
@A.Ellett If the questions and answers will be labelled, then it's a good idea indeed. I added a version with that. Thanks :)
â Phelype Oleinik
Sep 10 at 23:22
add a comment |Â
up vote
3
down vote
You have several options.
- The simplest is: Define your own command, say
questionVSpace
, to use a space between elements within a list. Observe that the definition of vertical space command may depend on the class you use. - There are more elaborate ways to do it. I recommend using a command for doing so. This command should handle the vertical space automatically and should handle layout issues globally, e.g. if you want to change "Q." to "Question". A crude but more useful way is my second variant. This also allows to enumerate the question, see my code below.
These variants are implemented in the following MWE.
documentclassarticle
%you can manually choose a space here if you do not like the predefined ones
%In case you want to use one of the predfined ones, say smallskip, you should still use questionVSpace and replace vspace9ex with smallskip
newcommandquestionVSpacevspace9ex
newcounterquestionCounter
newcommandqAndA[2]
%The following code automatically adds the space unless it is the first question.
ifnumvaluequestionCounter>0
bigskip%you can choose a different space here.
fi
stepcounterquestionCounter
% You could also change "Q." to "Q. thequestionCounter"
item[Q.] #1
item[A.] #2
begindocument
sectionVariant A
Test
beginitemize
item[Q.] Question 1
item[A.] Answer 1
smallskip
item[Q.] Question 2
item[A.] Answer 2
medskip
item[Q.] Question 3
item[A.] Answer 3
bigskip
item[Q.] Question 4
item[A.] Answer 4
questionVSpace
item[Q.] Question 5
item[A.] Answer 5
enditemize
sectionVariant B
Test
beginitemize
qAndA Text fooText bar
qAndA Text fooText bar
qAndA Text fooText bar
enditemize
enddocument
1
I think you forgot something atifthequestionCounter
. This will always evaluate to false. See the extra vertical space between0.2 B
andQ. Text foo
.
â Phelype Oleinik
Sep 10 at 23:14
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
add a comment |Â
up vote
3
down vote
You have several options.
- The simplest is: Define your own command, say
questionVSpace
, to use a space between elements within a list. Observe that the definition of vertical space command may depend on the class you use. - There are more elaborate ways to do it. I recommend using a command for doing so. This command should handle the vertical space automatically and should handle layout issues globally, e.g. if you want to change "Q." to "Question". A crude but more useful way is my second variant. This also allows to enumerate the question, see my code below.
These variants are implemented in the following MWE.
documentclassarticle
%you can manually choose a space here if you do not like the predefined ones
%In case you want to use one of the predfined ones, say smallskip, you should still use questionVSpace and replace vspace9ex with smallskip
newcommandquestionVSpacevspace9ex
newcounterquestionCounter
newcommandqAndA[2]
%The following code automatically adds the space unless it is the first question.
ifnumvaluequestionCounter>0
bigskip%you can choose a different space here.
fi
stepcounterquestionCounter
% You could also change "Q." to "Q. thequestionCounter"
item[Q.] #1
item[A.] #2
begindocument
sectionVariant A
Test
beginitemize
item[Q.] Question 1
item[A.] Answer 1
smallskip
item[Q.] Question 2
item[A.] Answer 2
medskip
item[Q.] Question 3
item[A.] Answer 3
bigskip
item[Q.] Question 4
item[A.] Answer 4
questionVSpace
item[Q.] Question 5
item[A.] Answer 5
enditemize
sectionVariant B
Test
beginitemize
qAndA Text fooText bar
qAndA Text fooText bar
qAndA Text fooText bar
enditemize
enddocument
1
I think you forgot something atifthequestionCounter
. This will always evaluate to false. See the extra vertical space between0.2 B
andQ. Text foo
.
â Phelype Oleinik
Sep 10 at 23:14
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You have several options.
- The simplest is: Define your own command, say
questionVSpace
, to use a space between elements within a list. Observe that the definition of vertical space command may depend on the class you use. - There are more elaborate ways to do it. I recommend using a command for doing so. This command should handle the vertical space automatically and should handle layout issues globally, e.g. if you want to change "Q." to "Question". A crude but more useful way is my second variant. This also allows to enumerate the question, see my code below.
These variants are implemented in the following MWE.
documentclassarticle
%you can manually choose a space here if you do not like the predefined ones
%In case you want to use one of the predfined ones, say smallskip, you should still use questionVSpace and replace vspace9ex with smallskip
newcommandquestionVSpacevspace9ex
newcounterquestionCounter
newcommandqAndA[2]
%The following code automatically adds the space unless it is the first question.
ifnumvaluequestionCounter>0
bigskip%you can choose a different space here.
fi
stepcounterquestionCounter
% You could also change "Q." to "Q. thequestionCounter"
item[Q.] #1
item[A.] #2
begindocument
sectionVariant A
Test
beginitemize
item[Q.] Question 1
item[A.] Answer 1
smallskip
item[Q.] Question 2
item[A.] Answer 2
medskip
item[Q.] Question 3
item[A.] Answer 3
bigskip
item[Q.] Question 4
item[A.] Answer 4
questionVSpace
item[Q.] Question 5
item[A.] Answer 5
enditemize
sectionVariant B
Test
beginitemize
qAndA Text fooText bar
qAndA Text fooText bar
qAndA Text fooText bar
enditemize
enddocument
You have several options.
- The simplest is: Define your own command, say
questionVSpace
, to use a space between elements within a list. Observe that the definition of vertical space command may depend on the class you use. - There are more elaborate ways to do it. I recommend using a command for doing so. This command should handle the vertical space automatically and should handle layout issues globally, e.g. if you want to change "Q." to "Question". A crude but more useful way is my second variant. This also allows to enumerate the question, see my code below.
These variants are implemented in the following MWE.
documentclassarticle
%you can manually choose a space here if you do not like the predefined ones
%In case you want to use one of the predfined ones, say smallskip, you should still use questionVSpace and replace vspace9ex with smallskip
newcommandquestionVSpacevspace9ex
newcounterquestionCounter
newcommandqAndA[2]
%The following code automatically adds the space unless it is the first question.
ifnumvaluequestionCounter>0
bigskip%you can choose a different space here.
fi
stepcounterquestionCounter
% You could also change "Q." to "Q. thequestionCounter"
item[Q.] #1
item[A.] #2
begindocument
sectionVariant A
Test
beginitemize
item[Q.] Question 1
item[A.] Answer 1
smallskip
item[Q.] Question 2
item[A.] Answer 2
medskip
item[Q.] Question 3
item[A.] Answer 3
bigskip
item[Q.] Question 4
item[A.] Answer 4
questionVSpace
item[Q.] Question 5
item[A.] Answer 5
enditemize
sectionVariant B
Test
beginitemize
qAndA Text fooText bar
qAndA Text fooText bar
qAndA Text fooText bar
enditemize
enddocument
edited Sep 11 at 10:55
answered Sep 10 at 22:51
CampanIgnis
2,3362831
2,3362831
1
I think you forgot something atifthequestionCounter
. This will always evaluate to false. See the extra vertical space between0.2 B
andQ. Text foo
.
â Phelype Oleinik
Sep 10 at 23:14
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
add a comment |Â
1
I think you forgot something atifthequestionCounter
. This will always evaluate to false. See the extra vertical space between0.2 B
andQ. Text foo
.
â Phelype Oleinik
Sep 10 at 23:14
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
1
1
I think you forgot something at
ifthequestionCounter
. This will always evaluate to false. See the extra vertical space between 0.2 B
and Q. Text foo
.â Phelype Oleinik
Sep 10 at 23:14
I think you forgot something at
ifthequestionCounter
. This will always evaluate to false. See the extra vertical space between 0.2 B
and Q. Text foo
.â Phelype Oleinik
Sep 10 at 23:14
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
@PhelypeOleinik Than you very much. I hope it is fixed now.
â CampanIgnis
Sep 10 at 23:24
add a comment |Â
up vote
2
down vote
More simply, you could use a different itemize for each Q & A:
beginitemize
item[Q.] Question 1
item[A.] Answer 1
end[itemize}
beginitemize
item[Q.] Question 2
item[A.] Answer 2
enditemize
add a comment |Â
up vote
2
down vote
More simply, you could use a different itemize for each Q & A:
beginitemize
item[Q.] Question 1
item[A.] Answer 1
end[itemize}
beginitemize
item[Q.] Question 2
item[A.] Answer 2
enditemize
add a comment |Â
up vote
2
down vote
up vote
2
down vote
More simply, you could use a different itemize for each Q & A:
beginitemize
item[Q.] Question 1
item[A.] Answer 1
end[itemize}
beginitemize
item[Q.] Question 2
item[A.] Answer 2
enditemize
More simply, you could use a different itemize for each Q & A:
beginitemize
item[Q.] Question 1
item[A.] Answer 1
end[itemize}
beginitemize
item[Q.] Question 2
item[A.] Answer 2
enditemize
answered Sep 11 at 1:41
user94293
2,104414
2,104414
add a comment |Â
add a comment |Â
up vote
1
down vote
Here's an approach using a new environment called QA
. I've tried to throw in enough to let you see what's possible beyond just what you asked and to allow you to see where additional tweaks might enhance what you're doing. I've exaggerated the effect of adding vertical space between an answer and a following question: tweak to something more suitable.
documentclassarticle
newcounteraeQAcounter
newcounteraePAIRcounter
defaeRememberLastPair1
newenvironmentQA[1]
%% save the definition of `item` so I can access
%% its definition later when I *redefine* it.
letaeitemitem
%% a crude key value'ish approach to remembering
%% previous value for question/answer pair.
defaeTestA#1%%
defaeTestBremember previous%%
ifxaeTestAaeTestB
%% nothing to do here!!
else
defaeRememberLastPair1%%
fi
setcounteraePAIRcounteraeRememberLastPair%%
beginlist%%
sffamily
ifoddtheaeQAcounter Question theaePAIRcounter%%
else
Answer theaePAIRcounter%%
stepcounteraePAIRcounter%%
fi
:%%
usecounteraeQAcounter%%
defitem%%
%% only add space if not the first question
ifnumtheaePAIRcounter=aeRememberLastPair
%% do nothing!!!!
else
%% only add space before question and after
%% an answer (the even `item` in the list)
ifoddtheaeQAcounter
else
vspace4ex%%
fi
fi
aeitem
letquestionitem
letansweritem
xdefaeRememberLastPairtheaePAIRcounter%%
endlist
begindocument
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida mauris. Nam arcu
beginQA
question What do you say when you part from someone?
question bye
question What is a fruit that shouldn't be mixed with apples?
answer An orange.
endQA
Nam dui ligula, fringilla a, euismod sodales, sollicitudin
vel, wisi. Morbi auctor lorem non justo. Nam lacus libero,
pretium at, lobortis vitae, ultricies et.
textbfsffamily And, we continue with more questions:
beginQA[remember previous]
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
textbfsffamily And, Here is a new set of questions:
beginQA
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
enddocument
Notice that I use two counters here. One counter is essentially the list's counter for each item. If it's odd, that means I'm asking a question. If it's even, that means I'm answering a question. The second counter is only advanced once the question/answer pair has been established.
Also, notice that question
and answer
are stupid, in the sense that they're really just stand-ins for item
and don't do much else. Everything is handled through item
and tracking counters. I try to let the environment itself handle the tracking of questions and answers. The only difficulty comes when adding space. From within the list
environment's arguments, not much can be done.
One thing to note, you cannot insert vspace...
from within the first argument to the list
environment. It will do nothing there and just be ignored for the most part (or show up where you don't expect it).
add a comment |Â
up vote
1
down vote
Here's an approach using a new environment called QA
. I've tried to throw in enough to let you see what's possible beyond just what you asked and to allow you to see where additional tweaks might enhance what you're doing. I've exaggerated the effect of adding vertical space between an answer and a following question: tweak to something more suitable.
documentclassarticle
newcounteraeQAcounter
newcounteraePAIRcounter
defaeRememberLastPair1
newenvironmentQA[1]
%% save the definition of `item` so I can access
%% its definition later when I *redefine* it.
letaeitemitem
%% a crude key value'ish approach to remembering
%% previous value for question/answer pair.
defaeTestA#1%%
defaeTestBremember previous%%
ifxaeTestAaeTestB
%% nothing to do here!!
else
defaeRememberLastPair1%%
fi
setcounteraePAIRcounteraeRememberLastPair%%
beginlist%%
sffamily
ifoddtheaeQAcounter Question theaePAIRcounter%%
else
Answer theaePAIRcounter%%
stepcounteraePAIRcounter%%
fi
:%%
usecounteraeQAcounter%%
defitem%%
%% only add space if not the first question
ifnumtheaePAIRcounter=aeRememberLastPair
%% do nothing!!!!
else
%% only add space before question and after
%% an answer (the even `item` in the list)
ifoddtheaeQAcounter
else
vspace4ex%%
fi
fi
aeitem
letquestionitem
letansweritem
xdefaeRememberLastPairtheaePAIRcounter%%
endlist
begindocument
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida mauris. Nam arcu
beginQA
question What do you say when you part from someone?
question bye
question What is a fruit that shouldn't be mixed with apples?
answer An orange.
endQA
Nam dui ligula, fringilla a, euismod sodales, sollicitudin
vel, wisi. Morbi auctor lorem non justo. Nam lacus libero,
pretium at, lobortis vitae, ultricies et.
textbfsffamily And, we continue with more questions:
beginQA[remember previous]
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
textbfsffamily And, Here is a new set of questions:
beginQA
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
enddocument
Notice that I use two counters here. One counter is essentially the list's counter for each item. If it's odd, that means I'm asking a question. If it's even, that means I'm answering a question. The second counter is only advanced once the question/answer pair has been established.
Also, notice that question
and answer
are stupid, in the sense that they're really just stand-ins for item
and don't do much else. Everything is handled through item
and tracking counters. I try to let the environment itself handle the tracking of questions and answers. The only difficulty comes when adding space. From within the list
environment's arguments, not much can be done.
One thing to note, you cannot insert vspace...
from within the first argument to the list
environment. It will do nothing there and just be ignored for the most part (or show up where you don't expect it).
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Here's an approach using a new environment called QA
. I've tried to throw in enough to let you see what's possible beyond just what you asked and to allow you to see where additional tweaks might enhance what you're doing. I've exaggerated the effect of adding vertical space between an answer and a following question: tweak to something more suitable.
documentclassarticle
newcounteraeQAcounter
newcounteraePAIRcounter
defaeRememberLastPair1
newenvironmentQA[1]
%% save the definition of `item` so I can access
%% its definition later when I *redefine* it.
letaeitemitem
%% a crude key value'ish approach to remembering
%% previous value for question/answer pair.
defaeTestA#1%%
defaeTestBremember previous%%
ifxaeTestAaeTestB
%% nothing to do here!!
else
defaeRememberLastPair1%%
fi
setcounteraePAIRcounteraeRememberLastPair%%
beginlist%%
sffamily
ifoddtheaeQAcounter Question theaePAIRcounter%%
else
Answer theaePAIRcounter%%
stepcounteraePAIRcounter%%
fi
:%%
usecounteraeQAcounter%%
defitem%%
%% only add space if not the first question
ifnumtheaePAIRcounter=aeRememberLastPair
%% do nothing!!!!
else
%% only add space before question and after
%% an answer (the even `item` in the list)
ifoddtheaeQAcounter
else
vspace4ex%%
fi
fi
aeitem
letquestionitem
letansweritem
xdefaeRememberLastPairtheaePAIRcounter%%
endlist
begindocument
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida mauris. Nam arcu
beginQA
question What do you say when you part from someone?
question bye
question What is a fruit that shouldn't be mixed with apples?
answer An orange.
endQA
Nam dui ligula, fringilla a, euismod sodales, sollicitudin
vel, wisi. Morbi auctor lorem non justo. Nam lacus libero,
pretium at, lobortis vitae, ultricies et.
textbfsffamily And, we continue with more questions:
beginQA[remember previous]
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
textbfsffamily And, Here is a new set of questions:
beginQA
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
enddocument
Notice that I use two counters here. One counter is essentially the list's counter for each item. If it's odd, that means I'm asking a question. If it's even, that means I'm answering a question. The second counter is only advanced once the question/answer pair has been established.
Also, notice that question
and answer
are stupid, in the sense that they're really just stand-ins for item
and don't do much else. Everything is handled through item
and tracking counters. I try to let the environment itself handle the tracking of questions and answers. The only difficulty comes when adding space. From within the list
environment's arguments, not much can be done.
One thing to note, you cannot insert vspace...
from within the first argument to the list
environment. It will do nothing there and just be ignored for the most part (or show up where you don't expect it).
Here's an approach using a new environment called QA
. I've tried to throw in enough to let you see what's possible beyond just what you asked and to allow you to see where additional tweaks might enhance what you're doing. I've exaggerated the effect of adding vertical space between an answer and a following question: tweak to something more suitable.
documentclassarticle
newcounteraeQAcounter
newcounteraePAIRcounter
defaeRememberLastPair1
newenvironmentQA[1]
%% save the definition of `item` so I can access
%% its definition later when I *redefine* it.
letaeitemitem
%% a crude key value'ish approach to remembering
%% previous value for question/answer pair.
defaeTestA#1%%
defaeTestBremember previous%%
ifxaeTestAaeTestB
%% nothing to do here!!
else
defaeRememberLastPair1%%
fi
setcounteraePAIRcounteraeRememberLastPair%%
beginlist%%
sffamily
ifoddtheaeQAcounter Question theaePAIRcounter%%
else
Answer theaePAIRcounter%%
stepcounteraePAIRcounter%%
fi
:%%
usecounteraeQAcounter%%
defitem%%
%% only add space if not the first question
ifnumtheaePAIRcounter=aeRememberLastPair
%% do nothing!!!!
else
%% only add space before question and after
%% an answer (the even `item` in the list)
ifoddtheaeQAcounter
else
vspace4ex%%
fi
fi
aeitem
letquestionitem
letansweritem
xdefaeRememberLastPairtheaePAIRcounter%%
endlist
begindocument
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida mauris. Nam arcu
beginQA
question What do you say when you part from someone?
question bye
question What is a fruit that shouldn't be mixed with apples?
answer An orange.
endQA
Nam dui ligula, fringilla a, euismod sodales, sollicitudin
vel, wisi. Morbi auctor lorem non justo. Nam lacus libero,
pretium at, lobortis vitae, ultricies et.
textbfsffamily And, we continue with more questions:
beginQA[remember previous]
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
textbfsffamily And, Here is a new set of questions:
beginQA
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
question Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
answer Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatib
endQA
enddocument
Notice that I use two counters here. One counter is essentially the list's counter for each item. If it's odd, that means I'm asking a question. If it's even, that means I'm answering a question. The second counter is only advanced once the question/answer pair has been established.
Also, notice that question
and answer
are stupid, in the sense that they're really just stand-ins for item
and don't do much else. Everything is handled through item
and tracking counters. I try to let the environment itself handle the tracking of questions and answers. The only difficulty comes when adding space. From within the list
environment's arguments, not much can be done.
One thing to note, you cannot insert vspace...
from within the first argument to the list
environment. It will do nothing there and just be ignored for the most part (or show up where you don't expect it).
edited Sep 11 at 2:06
answered Sep 11 at 0:56
A.Ellett
34.7k1063162
34.7k1063162
add a comment |Â
add a comment |Â
up vote
1
down vote
The space between items is controlled by itemsep
, so you can fix for each item, with the advantage that your Q & A lists will not influenced by the default itemsep
as it would happen using some additional vertical space as vspace
,bigskip
. I will add some glue too, not a fixed length, that would help to avoid orphan items/lines.
This can be done easily as already proposed making a macro for each item type, and I think that semantically is better that a complex redefine of item
type to hiddenly switch from "Q." to "A.". With the "keep it simple" principle in mind, I do not see the need of conditionals or counters (I will edit the answer if you clarify this point), so the macros could be some like this:
documentclassarticle
newcommandQ[1]item[bfseries Q.]
itemsep2pt plus 2pt #1
newcommandA[1]item[bfseries A.]
itemsep1em plus .2em minus .1em #1
newenvironmentq-asection*Questions
and answersbeginitemizeenditemize
begindocument
beginq-a
Q Question 1
A Answer 1
Q Question 2
A Answer 2
Q Question 3
A Answer 3
endq-a
enddocument
add a comment |Â
up vote
1
down vote
The space between items is controlled by itemsep
, so you can fix for each item, with the advantage that your Q & A lists will not influenced by the default itemsep
as it would happen using some additional vertical space as vspace
,bigskip
. I will add some glue too, not a fixed length, that would help to avoid orphan items/lines.
This can be done easily as already proposed making a macro for each item type, and I think that semantically is better that a complex redefine of item
type to hiddenly switch from "Q." to "A.". With the "keep it simple" principle in mind, I do not see the need of conditionals or counters (I will edit the answer if you clarify this point), so the macros could be some like this:
documentclassarticle
newcommandQ[1]item[bfseries Q.]
itemsep2pt plus 2pt #1
newcommandA[1]item[bfseries A.]
itemsep1em plus .2em minus .1em #1
newenvironmentq-asection*Questions
and answersbeginitemizeenditemize
begindocument
beginq-a
Q Question 1
A Answer 1
Q Question 2
A Answer 2
Q Question 3
A Answer 3
endq-a
enddocument
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The space between items is controlled by itemsep
, so you can fix for each item, with the advantage that your Q & A lists will not influenced by the default itemsep
as it would happen using some additional vertical space as vspace
,bigskip
. I will add some glue too, not a fixed length, that would help to avoid orphan items/lines.
This can be done easily as already proposed making a macro for each item type, and I think that semantically is better that a complex redefine of item
type to hiddenly switch from "Q." to "A.". With the "keep it simple" principle in mind, I do not see the need of conditionals or counters (I will edit the answer if you clarify this point), so the macros could be some like this:
documentclassarticle
newcommandQ[1]item[bfseries Q.]
itemsep2pt plus 2pt #1
newcommandA[1]item[bfseries A.]
itemsep1em plus .2em minus .1em #1
newenvironmentq-asection*Questions
and answersbeginitemizeenditemize
begindocument
beginq-a
Q Question 1
A Answer 1
Q Question 2
A Answer 2
Q Question 3
A Answer 3
endq-a
enddocument
The space between items is controlled by itemsep
, so you can fix for each item, with the advantage that your Q & A lists will not influenced by the default itemsep
as it would happen using some additional vertical space as vspace
,bigskip
. I will add some glue too, not a fixed length, that would help to avoid orphan items/lines.
This can be done easily as already proposed making a macro for each item type, and I think that semantically is better that a complex redefine of item
type to hiddenly switch from "Q." to "A.". With the "keep it simple" principle in mind, I do not see the need of conditionals or counters (I will edit the answer if you clarify this point), so the macros could be some like this:
documentclassarticle
newcommandQ[1]item[bfseries Q.]
itemsep2pt plus 2pt #1
newcommandA[1]item[bfseries A.]
itemsep1em plus .2em minus .1em #1
newenvironmentq-asection*Questions
and answersbeginitemizeenditemize
begindocument
beginq-a
Q Question 1
A Answer 1
Q Question 2
A Answer 2
Q Question 3
A Answer 3
endq-a
enddocument
edited Sep 11 at 8:07
answered Sep 11 at 7:53
Fran
48.5k6110170
48.5k6110170
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f450319%2fspacing-between-groups-of-two-list-items%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Welcome to TeX.SX! A hackish way would be to insert
vspace<some amount>
there. For example,vspace0.25cm
. This would be quite boring for longer lists though...â Phelype Oleinik
Sep 10 at 22:48