2

I am working on table in which the last column is wrapped with a command \Addbreakable. I need to color alternate rows as well. But I can do either \Addbrekable or coloring alternate rows.

Note:

Below is my sample example.

\documentclass{article}
\usepackage{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[margin=1.2cm]{geometry}
\usepackage{framed}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage{hyphenat}
\usepackage{xstring}
\usepackage{forloop}
\usepackage{collcell}
\usepackage[table]{xcolor}
\definecolor{Gray}{gray}{0.9}

\definecolor{LightCyan}{rgb}{0.88,1,1} \newsavebox\MyBreakChar% \sbox\MyBreakChar{}% char to display the break after non char \newsavebox\MySpaceBreakChar% \sbox\MySpaceBreakChar{-}% char to display the break after space \makeatletter% \newcommand*{\BreakableChar}[1][\MyBreakChar]{% \leavevmode% \prw@zbreak% \discretionary{\usebox#1}{}{}% \prw@zbreak% }%

\newcounter{index}% \newcommand{\AddBreakableChars}[1]{% \StrLen{#1 }[\stringLength]% \forloop[1]{index}{1}{\value{index}<\stringLength}{% \StrChar{#1}{\value{index}}[\currentLetter]% \IfStrEq{\currentLetter}{]} {\currentLetter\BreakableChar[\MyBreakChar]}% {\currentLetter}% }% }%

\begin{document} \textbf{Manual Solution:} \newline \begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=yellow,outerlinewidth=.5, innerleftmargin=8, innertopmargin=8,innerbottommargin=8, everyline = true] %\begin{tabular}{>{\rule{0pt}{.5cm}}>{\arraybackslash}p{8cm}c|> {\arraybackslash}p{1cm}c|>{\arraybackslash}p{1cm}c|>{\arraybackslash}p{1cm}c|>{\arraybackslash}p{2cm}c}

\rowcolors{2}{gray!25}{white} \begin{tabular}{p{2cm}p{2cm}p{6cm}p{2cm}p{2cm}} \rowcolor{yellow} Col1 & Col2 & Col3 & Col4 & Col5\ test & data & data & data &\AddBreakableChars{[1][7][3][8][5][9][7][8][9][89][100]}\ test & data & data & data &\AddBreakableChars{[1][7][3][8][5][9][7][8][9][89][100]}\

\end{tabular} \end{mdframed} \vspace{1mm} \begin{mdframed}[roundcorner=10pt,leftmargin=1.0, rightmargin=1.0, linecolor=red,outerlinewidth=.5, innerleftmargin=8, innertopmargin=8,innerbottommargin=8]

\centering \rowcolors{2}{green}{white} \begin{tabular}{>{\rule{0pt}{.5cm}}>{\arraybackslash}p{2.25 cm}>{\arraybackslash}p{2.25cm}c>{\arraybackslash}p{8cm}c>{\arraybackslash}p{2cm}c} \rowcolor{yellow} \textbf{Col1} &\textbf{Col2} &\textbf{Col3} &\textbf{Col4} &\textbf{Col5}\ \hline ERBB3 & TT2292239& TQWT & Grammar. a grammatical unit of one or more words that expresses an independent statement, question, request, command, exclamation, etc. & \AddBreakableChars{[1][2][3][4][5][6][7][8][9][10][11][12][13][14]} \ & TT2296336& CQWG & Grammar. a grammatical unit of one or more words that expresses an independent statement, question, request, command, exclamation, etc. & \AddBreakableChars{[1][2][3][4][5][6][7][8][9][10][11][12][13][14]} \ \end{tabular} \end{mdframed} \end{document}

Please help me out of this problem. I have tried many methods but nothing seems to be working fine.

manish
  • 9,111
  • I just edited my post with more complete example. – manish Jun 29 '12 at 01:53
  • That is not quite a minimal example. You should eliminate packages that are not required to reproduce this problem. Also do you need all those rows to reproduce the problem - wont 3-4 do? – Peter Grill Jun 29 '12 at 02:09
  • Thanks for suggestion. I have removed extra package and rows to make MWE. – manish Jun 29 '12 at 02:31
  • Why is the graphicx package required? Is mdframed required to reproduce the problem? Also your example does not compile: \rowcolors is undefined. – Peter Grill Jun 29 '12 at 02:33
  • It is part of my program so i want to test table in mdframed. For rowcolor i just added \usepackage[table]{xcolor} but still same pblm. – manish Jun 29 '12 at 02:38
  • Your revised code works if you move the \usepackage[table]{xcolor} up to the top. If the problem can be reproduced without a package, that package should be removed in the MWE. – Peter Grill Jun 29 '12 at 02:46
  • Thanks it works but in first table cell height is very small. i want to provide some width myself like i did in second table. But with second i cannot wrap last column. – manish Jun 29 '12 at 03:11
  • I found solution. Thank you very much for your reply. – manish Jun 29 '12 at 03:20

1 Answers1

3

The reason why your last version was not working properly was that your table column specification were incorrect. Once you make the column p{2.0cm} things work just fine:

enter image description here

Notes:

  • I have reformatted the column specification which should make it easier to read. In your version you should notice that there are extra c column type specification.
  • I also moved the loading of \usepackage[table]{xcolor} so that there are no package option conflicts.
  • Two @{} were to the table column specification in order to eliminate the additional column spacing before the first and after the last column. This eliminates the Overfull \hbox warnings. You could actually just use a l for columns 1,2, and 3 which would produce a not so wide table.
  • The showframe package was used to display the page margins.

Code:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[margin=1.2cm]{geometry}
\usepackage{framed}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage{hyphenat}
\usepackage{xstring}
\usepackage{forloop}
\usepackage{collcell}
\definecolor{Gray}{gray}{0.9}

\definecolor{LightCyan}{rgb}{0.88,1,1} \newsavebox\MyBreakChar% \sbox\MyBreakChar{}% char to display the break after non char \newsavebox\MySpaceBreakChar% \sbox\MySpaceBreakChar{-}% char to display the break after space \makeatletter% \newcommand*{\BreakableChar}[1][\MyBreakChar]{% \leavevmode% \prw@zbreak% \discretionary{\usebox#1}{}{}% \prw@zbreak% }%

\newcounter{index}% \newcommand{\AddBreakableChars}[1]{% \StrLen{#1 }[\stringLength]% \forloop[1]{index}{1}{\value{index}<\stringLength}{% \StrChar{#1}{\value{index}}[\currentLetter]% \IfStrEq{\currentLetter}{]} {\currentLetter\BreakableChar[\MyBreakChar]}% {\currentLetter}% }% }%

\begin{document} \begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=yellow,outerlinewidth=.5, innerleftmargin=8, innertopmargin=8,innerbottommargin=8, everyline = true] %\begin{tabular}{>{\rule{0pt}{.5cm}}>{\arraybackslash}p{8cm}c|> {\arraybackslash}p{1cm}c|>{\arraybackslash}p{1cm}c|>{\arraybackslash}p{1cm}c|>{\arraybackslash}p{2cm}c}

\rowcolors{2}{gray!25}{white} \begin{tabular}{p{2cm}p{2cm}p{6cm}p{2cm}p{2cm}} \rowcolor{yellow} Col1 & Col2 & Col3 & Col4 & Col5\ test & data & data & data &\AddBreakableChars{[1][7][3][8][5][9][7][8][9][89][100]}\ test & data & data & data &\AddBreakableChars{[1][7][3][8][5][9][7][8][9][89][100]}\

\end{tabular} \end{mdframed} \vspace{1mm} \begin{mdframed}[roundcorner=10pt,leftmargin=1.0, rightmargin=1.0, linecolor=red,outerlinewidth=.5, innerleftmargin=8, innertopmargin=8,innerbottommargin=8]

\centering \rowcolors{2}{green}{white} \begin{tabular}{@{} >{\rule{0pt}{.5cm}}>{\arraybackslash}p{2.25 cm} >{\arraybackslash}p{2.25cm} >{\arraybackslash}p{2cm} >{\arraybackslash}p{8cm} >{\arraybackslash}p{2cm}@{} } \rowcolor{yellow} \textbf{Col1} &\textbf{Col2} &\textbf{Col3} &\textbf{Col4} &\textbf{Col5}\ \hline ERBB3 & TT2292239& TQWT & Grammar. a grammatical unit of one or more words that expresses an independent statement, question, request, command, exclamation, etc. & \AddBreakableChars{[1][2][3][4][5][6][7][8][9][10][11][12][13][14]} \ & TT2296336& CQWG & Grammar. a grammatical unit of one or more words that expresses an independent statement, question, request, command, exclamation, etc. & \AddBreakableChars{[1][2][3][4][5][6][7][8][9][10][11][12][13][14]} \ \end{tabular} \end{mdframed} \end{document}

Peter Grill
  • 223,288