Text FormattingSpacing issues with inline tables

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
OsakaWebbie
Posts: 9
Joined: Thu Apr 19, 2012 2:56 am

Spacing issues with inline tables

Post by OsakaWebbie »

I'm trying to use LaTeX (well, technically upLaTeX, but that shouldn't matter for this question) to create song sheets with chords above the lyrics (I'll be generating the tex files programatically from a database). I'm using little {tabular} pieces inline to line up the chords, and as much as possible I'm trying to consolidate all the sizing/appearance items in one place (similar to paragraph styles in desktop software or CSS in web design), so I define several new commands to keep it neat and tidy. But I'm having trouble with a couple things.

Here's my preamble plus some content to demonstrate what's going on:

Code: Select all

\documentclass[12pt,twocolumn]{ujarticle}
\usepackage[paperwidth=210mm,paperheight=297mm,margin=6mm]{geometry}
\pagestyle{empty}
\usepackage{color}
\usepackage{parskip}
\newcommand{\stanza}[1]{#1\vskip 8pt}
\newcommand{\songtitle}[1]{\textcolor{blue}{\textbf{\Large #1}}\vskip 0pt\nopagebreak}
\newcommand{\chord}[1]{\textcolor{red}{\textbf{#1}}}
\newcommand{\chordset}[2]{\hangindent=10mm\begin{tabular}[b]{l}\chord{#1}\\#2\end{tabular}}

\begin{document}
\sffamily
\raggedright
\raggedbottom
\clubpenalty 1000
\widowpenalty 1000
\setlength{\tabcolsep}{0mm}
\def\arraystretch{0.7}

\songtitle{As The Deer}
\stanza{
\chordset{D}{As the }\chordset{A/C\textsuperscript{\#}}{deer panteth }\chordset{Bm}{for the }\chordset{D/A}{water}\\[6pt]
\chordset{D}{As the\ }\chordset{A/C\textsuperscript{\#}}{deer panteth\ }\chordset{Bm}{for the\ }\chordset{D/A}{water}\\[6pt]
\chordset{D}{As the} \chordset{A/C\textsuperscript{\#}}{deer panteth} \chordset{Bm}{for the} \chordset{D/A}{water}\\[6pt]
So my\chordset{G}{soul }longeth \chordset{Asus A}{after }\chordset{D G/A A}{thee}\\
\chordset{D}{You al}\chordset{A/C\textsuperscript{\#}}{one are my }\chordset{Bm}{heart's de}\chordset{D/A}{sire}\\
And I \chordset{G}{long to }\chordset{A}{worship }\chordset{D}{Thee}
}
\stanza{
\chordset{Bm}{You alone are my }\chordset{G}{strength, my }\chordset{D}{shield}\\
To \chordset{G}{You alone may my }\chordset{Em}{spirit }\chordset{F\textsuperscript{\#}sus F\textsuperscript{\#}}{yield}\\
\chordset{D}{You al}\chordset{A/C\textsuperscript{\#}}{one are my }\chordset{Bm}{heart's de}\chordset{D/A}{sire}\\
And I \chordset{G}{long to }\chordset{A}{worship }\chordset{D}{Thee}
}

\songtitle{As The Deer}
\stanza{
\chordset{D}{As the }\chordset{A/C\#}{deer panteth }\chordset{Bm}{for the }\chordset{D/A}{water, }
so my\chordset{G}{soul }longeth \chordset{Asus A}{after }\chordset{D G/A A}{thee}\\
\chordset{D}{You al}\chordset{A/C\#}{one are my }\chordset{Bm}{heart's de}\chordset{D/A}{sire, and I }
\chordset{G}{long to }\chordset{A}{worship }\chordset{D}{Thee}}
\end{document}
A screenshot of the result is attached.

Problem #1: I can't figure out how to get spaces at the end of my table cell content to be honored. A plain space is ignored (line 1), and even "\ " is ignored (line 2). If I put the space outside the table (line 3), the space is overly big for some reason.

Problem #2: I want a bit more line spacing, but only between lines of lyrics, not between the chords and the lyrics below. \linespread affects the text inside the tables, pushing the chords away from the lyrics, so that won't do. \parskip seems to only affect the song titles and stanzas, not the lines in between. Putting something like "\\[6pt]" at the end of each line works (see lines 1-3), but (a) I would prefer to consolidate that formatting in one place, and (b) when long lines wrap (see the end of my demo content where I intentionally made the lines long to test my hanging indent), my first choice would be nice to have the spacing there too (although I could live without that). If \linespread could be repeatedly used inside the document (instead of just in the preamble), I could make it zero inside my definition of "\chordset" to unspread the text in the tables. The setspace package is supposed to be the solution to that, but it only has three choices for the amount of space.

Any ideas on these two issues? I'm very new to the whole TeX world, so if I'm doing other things wrong, please tell me that too...
Attachments
songsheet.png
songsheet.png (32.46 KiB) Viewed 7124 times
Last edited by Stefan Kottwitz on Thu May 10, 2012 9:19 am, edited 2 times in total.

Recommended reading 2024:

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

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

OsakaWebbie
Posts: 9
Joined: Thu Apr 19, 2012 2:56 am

Re: Spacing issues with inline tables

Post by OsakaWebbie »

Hmm, no thoughts on this? I especially have to solve Problem #1 before I can proceed with my project, so I hope someone has some insight.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Spacing issues with inline tables

Post by Juanjo »

Check the following code:

Code: Select all

\documentclass[a5paper,12pt,twocolumn]{article}
\usepackage[margin=6mm]{geometry}
\usepackage{color}

\newcommand\Sharp{\ensuremath{\sharp}}
\newcommand{\songtitle}[1]{\subsubsection*{%
   \normalfont\color{blue}\sffamily\bfseries\Large #1}}
\newcommand{\chord}[1]{\textcolor{red}{\textbf{#1}}}
\newcommand{\chordset}[2]{%
   \begin{tabular}[b]{@{}l@{}}\chord{#1}\\[-0.5ex]#2\end{tabular}}

\newcommand{\stanza}{\item\relax}
\newenvironment{song}
   {\begin{list}{}{%
      \setlength{\itemsep}{1ex} % Change to vary space between stanzas
      \setlength{\labelwidth}{0pt}
      \setlength{\labelsep}{0pt}
      \setlength{\leftmargin}{2em} % Change to modify indentation of 
                                   % long verses
      \setlength{\itemindent}{-\leftmargin}
      \setlength{\listparindent}{-\leftmargin}}}
   {\end{list}}               

\begin{document}

\sffamily
\raggedright
\pagestyle{empty}    
    
\songtitle{As The Deer}

\begin{song}

\stanza
\chordset{D}{As the} \chordset{A/C\Sharp}{deer panteth} 
   \chordset{Bm}{for the} \chordset{D/A}{water} \\
\chordset{D}{As the} \chordset{A/C\Sharp}{deer panteth} 
   \chordset{Bm}{for the} \chordset{D/A}{water} \\
\chordset{D}{As the} \chordset{A/C\Sharp}{deer panteth}
   \chordset{Bm}{for the} \chordset{D/A}{water} \\
So my \chordset{G}{soul} longeth \chordset{Asus A}{after}
   \chordset{D G/A A}{thee}\\
\chordset{D}{You al}\chordset{A/C\Sharp}{one are my}
   \chordset{Bm}{heart's de}\chordset{D/A}{sire} \\
And I \chordset{G}{long to} \chordset{A}{worship} \chordset{D}{Thee}

\stanza
\chordset{Bm}{You alone are my} \chordset{G}{strength, my}
   \chordset{D}{shield} \\
To \chordset{G}{You alone may my} \chordset{Em}{spirit}
   \chordset{F\Sharp sus F\Sharp}{yield} \\
\chordset{D}{You al}\chordset{A/C\Sharp}{one are my}
   \chordset{Bm}{heart's de}\chordset{D/A}{sire} \\
And I \chordset{G}{long to} \chordset{A}{worship} \chordset{D}{Thee}

\stanza
\chordset{Bm}{You alone are my} \chordset{G}{strength, my}
   \chordset{D}{shield} \\
To \chordset{G}{You alone may my} \chordset{Em}{spirit}
   \chordset{F\Sharp sus F\Sharp}{yield} \\
\chordset{D}{You al}\chordset{A/C\Sharp}{one are my}
   \chordset{Bm}{heart's de}\chordset{D/A}{sire} \\
And I \chordset{G}{long to} \chordset{A}{worship} \chordset{D}{Thee}

\end{song}


\songtitle{As The Deer}

\begin{song}

\stanza
\chordset{D}{As the}\chordset{A/C\Sharp}{deer panteth}
   \chordset{Bm}{for the}\chordset{D/A}{water,}
   so my \chordset{G}{soul} longeth \chordset{Asus A}{after}
   \chordset{D G/A A}{thee} \\
\chordset{D}{You al}\chordset{A/C\Sharp}{one are my}
   \chordset{Bm}{heart's de}\chordset{D/A}{sire, and I}
   \chordset{G}{long to} \chordset{A}{worship} \chordset{D}{Thee}
   
\end{song}

\end{document}
The fact that you use upTeX is relevant, since the ujarticle document class is not readily avalaible. So I use article instead. Please note that songs are now written as a list, the \stanza command playing the role of \item. This allows you to easily modify spacing and margins.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
OsakaWebbie
Posts: 9
Joined: Thu Apr 19, 2012 2:56 am

Spacing issues with inline tables

Post by OsakaWebbie »

I like that! I have only been working with TeX for about three weeks (and not full time), so I'm really green. Studying that code gave me a jump start on learning several things, including things I didn't ask about. For example, how did you know I was also struggling to get good-looking sharps and flats? :D

Three followup questions:
  1. I see that "[-0.5ex]\lyric{#2}" is how I reduce the space between the chords and lyrics - very nice. But if I also wanted to adjust (usually increase) the space between lines (within a stanza, but outside the little tables), what parameter/setting would I use?
  2. You omitted "\raggedbottom", "\clubpenalty 1000", and "\widowpenalty 1000". I tried putting them back in, but they don't seem to work in this list context. How can I keep the first and last two lines of each stanza together, and also not have TeX try to spread out a column vertically to fill the space?
  3. What is the meaning of "{@{}l@{}}" in \begin{tabular}? It's impossible to Google that, as it's all punctuation!
Also, a couple things I learned by experimentation in the meantime:
  • The extra wide spaces I was struggling with were a fluke - somehow I got some sort of special spaces in my code. When I changed encoding from UTF-8 to ASCII they revealed themselves as non-ASCII, and when I replaced them with normal spaces, the layout looked better.
  • I also figured out that if I have some sort of function around the contents of a table cell, a trailing space will be honored, which was my first choice solution to problem #1, for reasons that are complex to explain. My text is already black by default, but this redundant command forces the spaces to be honored:

    Code: Select all

    \newcommand{\lyric}[1]{\textcolor{black}{#1}}
    \newcommand{\chordset}[2]{%
        \begin{tabular}[b]{@{}l@{}}\chord{#1}\\[-0.7ex]\lyric{#2}\end{tabular}}
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Spacing issues with inline tables

Post by Juanjo »

OsakaWebbie wrote: I see that "[-0.5ex]\lyric{#2}" is how I reduce the space between the chords and lyrics - very nice. But if I also wanted to adjust (usually increase) the space between lines (within a stanza, but outside the little tables), what parameter/setting would I use?
Load de setspace package and check this definition of song:

Code: Select all

\newenvironment{song}
   {\begin{list}{}{%
      \setlength{\itemsep}{1ex} % Change to vary space between stanzas
      \setlength{\labelwidth}{0pt}
      \setlength{\labelsep}{0pt}
      \setlength{\leftmargin}{2em} % Change to modify indentation of 
                                   % long verses
      \setlength{\itemindent}{-\leftmargin}
      \setlength{\listparindent}{-\leftmargin}}
      \begin{spacing}{2}                 % Space between lines
      \renewcommand{\arraystretch}{0.5}} % Vertical space in chords
   {\end{spacing}\end{list}}               
By default, the parameters for the spacing environment and \arraystretch are equal to 1. If you put the value x for spacing, then put 1/x for \arraystretch if you want to keep constant the vertical space inside chordsets. In the above code, I wrote 2 and 0.5, for example.
OsakaWebbie wrote: You omitted "\raggedbottom", "\clubpenalty 1000", and "\widowpenalty 1000". I tried putting them back in, but they don't seem to work in this list context. How can I keep the first and last two lines of each stanza together, and also not have TeX try to spread out a column vertically to fill the space?
Put them back. At least \raggedbottom works. I would have to experiment with the other parameters.
OsakaWebbie wrote: What is the meaning of "{@{}l@{}}" in \begin{tabular}? It's impossible to Google that, as it's all punctuation!
You have a lot of documentation in http://texdoc.net. See, for example, page 30 in the unofficial LaTeX manual.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
OsakaWebbie
Posts: 9
Joined: Thu Apr 19, 2012 2:56 am

Re: Spacing issues with inline tables

Post by OsakaWebbie »

Thanks again! It took me a while to get back to working on this project, but now I tried the setspace package and your suggested code, and it works. (It's a bit of a delicate balance between the three interplaying values: "[value]\lyric{#2}", "\begin{spacing}{value}", and "\renewcommand{\arraystretch}{value}". But I think I've got it.)

I now have some problems with line wrapping, but I'll save that for another thread if I can't figure it out.
Post Reply