2

Can someone help me? I am trying to wrap the text in each column so the last column has the largest width.

\documentclass{article}

\usepackage{makecell, tabularx}
\renewcommand\theadfont{\bfseries}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\begin{document}

\begin{table}
\footnotesize
\setlength\tabcolsep{3pt}
\begin{tabularx}{\textwidth}           {|*{6}{ L| } } 
    \hline
    \thead[b]{Risk}  
    &   \thead[b]{Likelihood}                        
    &   \thead[b]{Impact}                        
    &   \thead[b]{Overall}
    &   \thead[b]{Response}                                               
    \\ \hline
    Going over budget      
    &   M                          
    &   L
    &   M
    &   \textbf{Preventative:} Keep track of all spending and have clearance of all potential spending by all project team members as well as the sponsor.
    \\ \hline
    Not having staff ambassadors
    &   M    
    &   L                           
    &   M
    &   \textbf{Preventative:} Ask as many staff members as possible to maximise the chances of having staff agreeing to represent their school. 
    \\ \hline
    Small turnout for event                
    &   M                         
    &   M
    &   M
    &   \textbf{Preventative:} Raise awareness for the event for at least a month in advance and continue to raise awareness.\newline \textbf{Opportunity:} Allows for a more intimate event and gain detailed attendee feedback                                                    
    \\ \hline
    Not meeting project event deadline                
    &    L
    &    H
    &    M
    &   \textbf{Preventive:} Ensure that all project team members meet their individual task deadlines and allow for some float time by constructing a critical path analysis
    \\ \hline
    Reaching venue capacity               
    &    M
    &    H
    &    M
    &   \textbf{Preventive:} Have attendees RSVP to the event to give an indication of numbers for the event which will allow the project team \newline 
    \textbf{Opportunity:} Allows for a bigger audience for the team to deliver the presentation to and create greater awareness of the collaboration tool.
    \\ \hline
    Technical issues during showcase              
    &    H
    &    H
    &    H
    &   \textbf{Preventive:} test all technical equipment before event begins\newline
    \textbf{Corrective:} have back-up devices ready \newline
    Connect to mobile phone internet 
    \\ \hline
    Catering for event does not deliver              
    &    M
    &    L
    &    M
    &   \textbf{Preventive:} Confirm with catering providers that food and drink will be delivered on time\newline 
    \textbf{Corrective:  }
    \\ \hline
    Sponsor does not agree with event plans             
    &    L
    &    H
    &    M
    &   \textbf{Preventive:} have continuous communication with the sponsor and have them sign everything off
    \\ \hline   
\end{tabularx}
\end{table}

\end{document}
Werner
  • 603,163
  • Where do you get \thead and the column type L from? Please provide all the necessary information so we can copy-and-paste-and-compile your code... not just a code snippet. – Werner Nov 02 '16 at 18:09
  • @Werner sorry, just added it now – Nessa Nguyen Nov 02 '16 at 18:12
  • 1
    It's unfortunate that you didn't read my comment suggesting you provide all the necessary information. What \documentclass are you using? Where does cmptable come from? I know it may not be necessary for this question, but it'll make your problem easily reproducable. – Werner Nov 02 '16 at 18:13
  • Hi @Werner I was provided with a cmp cls file which has over 1000 lines. I did not want to spam this forum and thought it would be best to just have a snippet. All I need to know is how to change the column width so that the last column is the biggest. – Nessa Nguyen Nov 02 '16 at 18:16
  • @Werner: \thead is defined by makecell. – Bernard Nov 02 '16 at 18:17
  • By asking for the \documentclass, I'm not asking you to post 1000 lines from some .cls. But you can at least provide the name. All we need to know are the details... I'll fix up your code to show you what you should provide... – Werner Nov 02 '16 at 18:17
  • @werner \documentclass[final]{nbsreport} – Nessa Nguyen Nov 02 '16 at 18:19
  • Why are the columns two to four are not using column type l, c, or r? – Heiko Oberdiek Nov 02 '16 at 18:20
  • @HeikoOberdiek I have tried. I am not sure and just want to make sure the text wraps so that they all are the min size they need. – Nessa Nguyen Nov 02 '16 at 18:23

2 Answers2

2

The following uses a fixed-width column for the first column - p{<len>}, followed by three centred columns and a final X-like column (that uses a \raggedright alignment:

enter image description here

\documentclass{article}

\usepackage{makecell, tabularx}
\renewcommand\theadfont{\bfseries}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\begin{document}

\noindent
\begingroup
\footnotesize
\setlength\tabcolsep{3pt}%
\begin{tabularx}{\linewidth}{ | >{\raggedright}p{5em} | *{3}{ c| } L| } 
    \hline
    \thead[b]{Risk}  
    &   \thead[b]{Likelihood}                        
    &   \thead[b]{Impact}                        
    &   \thead[b]{Overall}
    &   \thead[b]{Response}                                               
    \\ \hline
    Going over budget      
    &   M                          
    &   L
    &   M
    &   \textbf{Preventative:} Keep track of all spending and have clearance of all potential spending by all project team members as well as the sponsor.
    \\ \hline
    Not having staff ambassadors
    &   M    
    &   L                           
    &   M
    &   \textbf{Preventative:} Ask as many staff members as possible to maximise the chances of having staff agreeing to represent their school. 
    \\ \hline
    Small turnout for event                
    &   M                         
    &   M
    &   M
    &   \textbf{Preventative:} Raise awareness for the event for at least a month in advance and continue to raise awareness.\newline \textbf{Opportunity:} Allows for a more intimate event and gain detailed attendee feedback                                                    
    \\ \hline
    Not meeting project event deadline                
    &    L
    &    H
    &    M
    &   \textbf{Preventive:} Ensure that all project team members meet their individual task deadlines and allow for some float time by constructing a critical path analysis
    \\ \hline
    Reaching venue capacity               
    &    M
    &    H
    &    M
    &   \textbf{Preventive:} Have attendees RSVP to the event to give an indication of numbers for the event which will allow the project team \newline 
    \textbf{Opportunity:} Allows for a bigger audience for the team to deliver the presentation to and create greater awareness of the collaboration tool.
    \\ \hline
    Technical issues during showcase              
    &    H
    &    H
    &    H
    &   \textbf{Preventive:} test all technical equipment before event begins\newline
    \textbf{Corrective:} have back-up devices ready \newline
    Connect to mobile phone internet 
    \\ \hline
    Catering for event does not deliver              
    &    M
    &    L
    &    M
    &   \textbf{Preventive:} Confirm with catering providers that food and drink will be delivered on time\newline 
    \textbf{Corrective:  }
    \\ \hline
    Sponsor does not agree with event plans             
    &    L
    &    H
    &    M
    &   \textbf{Preventive:} have continuous communication with the sponsor and have them sign everything off
    \\ \hline   
\end{tabularx}
\endgroup

\end{document}

You can fiddle with the length <len> to suit your needs.

Note that your table only has five columns (you've set *{6}{..}). Also, I've used a % after \setlength{\tabcolsep}{3pt} as it introduces a spurious space that you want to avoid.

Werner
  • 603,163
2

Or alternatively resize L column type:

\documentclass{article}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\bfseries}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{rotating}

\usepackage{geometry}

\begin{document}
    \begin{table}[htb]
\caption{Risk Register \label{table6}}
\footnotesize
\setlength\tabcolsep{3pt}
\begin{tabularx}{\textwidth}{|>{\hsize=0.5\hsize}L|*{3}{ c| } >{\hsize=1.5\hsize}L | }
    \hline
    \thead{Risk}
    &   \thead{Likelihood}
    &   \thead{Impact}
    &   \thead{Overall}
    &   \thead{Response}
    \\ \hline
    Going over budget
    &   M
    &   L
    &   M
    &   \textbf{Preventative:} Keep track of all spending and have clearance of all potential spending by all project team members as well as the sponsor.
    \\ \hline
    Not having staff ambassadors
    &   M
    &   L
    &   M
    &   \textbf{Preventative:} Ask as many staff members as possible to maximise the chances of having staff agreeing to represent their school.
    \\ \hline
    Small turnout for event
    &   M
    &   M
    &   M
    &   \textbf{Preventative:} Raise awareness for the event for at least a month in advance and continue to raise awareness.\newline \textbf{Opportunity:} Allows for a more intimate event and gain detailed attendee feedback
    \\ \hline
    Not meeting project event deadline
    &    L
    &    H
    &    M
    &   \textbf{Preventive:} Ensure that all project team members meet their individual task deadlines and allow for some float time by constructing a critical path analysis
    \\ \hline
    Reaching venue capacity
    &    M
    &    H
    &    M
    &   \textbf{Preventive:} Have attendees RSVP to the event to give an indication of numbers for the event which will allow the project team \newline
    \textbf{Opportunity:} Allows for a bigger audience for the team to deliver the presentation to and create greater awareness of the collaboration tool.
    \\ \hline
    Technical issues during showcase
    &    H
    &    H
    &    H
    &   \textbf{Preventive:} test all technical equipment before event begins\newline
    \textbf{Corrective:} have back-up devices ready \newline
    Connect to mobile phone internet
    \\ \hline
    Catering for event does not deliver
    &    M
    &    L
    &    M
    &   \textbf{Preventive:} Confirm with catering providers that food and drink will be delivered on time\newline
    \textbf{Corrective:  }
    \\ \hline
    Sponsor does not agree with event plans
    &    L
    &    H
    &    M
    &   \textbf{Preventive:} have continuous communication with the sponsor and have them sign everything off
    \\ \hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

Zarko
  • 296,517