LaTeX forum ⇒ Graphics, Figures & TablesLongtables :: Setting 'global' properties

Information and discussion about graphics, figures & tables in LaTeX documents.
James Bejon
Posts: 1
Joined: Fri Jan 02, 2015 3:28 pm

Longtables :: Setting 'global' properties

Postby James Bejon » Fri Jan 02, 2015 3:47 pm

Dear All,

I’m completely new to tex. My level of ‘expertise’ is currently pasting text into TexShop (I have a Mac) and pressing “Typeset”. I’m hoping someone might be able to help me with a ‘long table’ related question. I want to set some general properties for my longtables so that their top row is always dark grey and so that they’re always horizontally-centred on my pages. I’ve found some documentation on longtables (http://tug.ctan.org/macros/latex/requir ... gtable.pdf), but I don’t yet have the know-how to make sense of it. I'd be very grateful if someone could give me a hand. Below is some code showing where I've got to so far.

James.

  1. % Type of doc.
  2. \documentclass[a4paper]{book}
  3.  
  4.  
  5. % General packages
  6. \usepackage[margin=1in]{geometry}
  7. \usepackage[pdftex]{graphicx}
  8. \usepackage[T1]{fontenc}
  9. \usepackage{pslatex}
  10. \usepackage[english]{babel}
  11. \usepackage{cjhebrew}
  12. \usepackage{parskip}
  13. \usepackage{enumerate}
  14.  
  15.  
  16. % Set for tables
  17. \usepackage{colortbl}
  18. \usepackage[table]{xcolor}
  19. \definecolor{lightgray}{gray}{0.95}
  20.  
  21. \usepackage{longtable,tabu}
  22. \usepackage{array} % for extrarowheight
  23. \renewcommand{\arraystretch}{1.5}
  24.  
  25.  
  26.  
  27. % Start doc.
  28. \begin{document}
  29.  
  30.  
  31. % Global font settings
  32. \renewcommand{\rmdefault}{ppl}
  33. \fontencoding{T1}
  34. \fontfamily{ppl}
  35. \fontsize{14}{18}
  36. \selectfont
  37.  
  38.  
  39. % Text
  40.  
  41. \chapter{Preface}
  42.  
  43. \section{Section 1}
  44.  
  45. Lots of text here. Lots of text here. Lots of text here. Lots of text here. Lots of text here. Lots of text here. Lots of text here.
  46.  
  47. \clearpage
  48.  
  49. \rowcolors{1}{}{lightgray}
  50. \begin{longtable}{|p{7.5cm}|p{7.5cm}|}
  51. \hline
  52.  
  53. \multicolumn{1}{|c}{\textbf{Col. 1}} & \multicolumn{1}{|c|}{\textbf{Col. 2}} \\ \hline
  54.  
  55. Text in Col 1. & Text in Col 2. \\ \hline
  56. Text in Col 1. & Text in Col 2. \\ \hline
  57. Text in Col 1. & Text in Col 2. \\ \hline
  58. Text in Col 1. & Text in Col 2. \\ \hline
  59. Text in Col 1. & Text in Col 2. \\ \hline
  60.  
  61. \hline
  62. \end{longtable}
  63.  
  64.  
  65. \end{document}

Tags:

Harish Kumar
Posts: 2
Joined: Sun Feb 22, 2015 1:39 am

Postby Harish Kumar » Sun Feb 22, 2015 8:37 am

What you have posted is not a Infominimal working example. Having said that, you are loading some packages which are not necessary to be loaded. For example

  1. % Set for tables
  2. \usepackage{colortbl} %% loaded by xcolor in next line, not needed
  3. \usepackage[table]{xcolor}
  4. \definecolor{lightgray}{gray}{0.95}
  5.  
  6. \usepackage{longtable,tabu} %% tabu is not needed
  7. \usepackage{array} % for extrarowheight %% not needed


Your first question can be solved by using the \rowcolor macro provided by xcolor

  1. \rowcolors{1}{gray}{} %%<-- colour alternate rows with gray colour starting from row 1.


Since you need to colour only the first row, issue \hiderowcolors after the first row.

And regarding your second question of "always horizontally-centred on my pages", some more clarification may be needed. At last, I don't think you can set the colouring properties globally to longtable.

  1. \documentclass[a4paper]{book}
  2. \usepackage[table]{xcolor}
  3. \usepackage{longtable}
  4. \renewcommand{\arraystretch}{1.5}
  5. \begin{document}
  6.  
  7. \rowcolors{1}{gray}{} %%<-- colour alternate rows with gray colour starting from row 1.
  8. \begin{longtable}{|p{7.5cm}|p{7.5cm}|}
  9. \hline
  10. \multicolumn{1}{|c|}{\textbf{Col. 1}} & \multicolumn{1}{c|}{\textbf{Col. 2}} \\ \hline
  11. \hiderowcolors %%% <--- hide row colours after this line
  12. Text in Col 1. & Text in Col 2. \\ \hline
  13. Text in Col 1. & Text in Col 2. \\ \hline
  14. Text in Col 1. & Text in Col 2. \\ \hline
  15. Text in Col 1. & Text in Col 2. \\ \hline
  16. Text in Col 1. & Text in Col 2. \\ \hline
  17. \hline
  18. \end{longtable}
  19. \end{document}


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 3 guests