Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a table containing a URL, and I want the URL to break so that the URL is right-justified along with the other text.

In my example below you can see that the last few lines are not right-justified:

I have tried to use \UrlBreaks to allow wrapping to occur using any character (see my code below), but this does not work.

Frankly, having the code be \raggedright would probably also be okay for my needs, but when I add \raggedright I get a bizarre linebreak inserted before the URL:

Any help to fix either scenario would be gratefully received!

Here's the code for the first example above:

\documentclass[10pt,letterpaper]{article}

\usepackage[hyphens]{url}
\urlstyle{same}
\usepackage{longtable}

\renewcommand{\UrlBreaks}{\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\/\do\-\do\_\do\:\do\.}

\begin{document}
\small

\begin{longtable}{@{}p{9.45cm}}

Craig Timberg, Jia Lynn Yang, and Hayley Tsukayama, ``Target says 40 million credit, debit cards may have been compromised in security breach'', \emph{The Washington Post}, December 19, 2013, available: \emph{\url{http://www.washingtonpost.com/business/technology/target-data-breach-affects-40-million-accounts-payment-info-compromised/2013/12/19/5cc71f22-68b1-11e3-ae56-22de072140a2_story.html}}. \\

\end{longtable}
\end{document}
share|improve this question
    
Welcome to TeX.SX! I believe, that the line-breaking for URLS does not differ from regular tabular environments and longtable environments (except from urls spanning over pages, but that is probably not the case) –  Christian Hupfer Aug 1 at 1:35
    
Hi! I'm using longtable because in my real document the table spans multiple pages, so it carried over to my example here. –  andrewinfosec Aug 1 at 3:43

1 Answer 1

How about

Mathematica graphics

ps. I do not think it is a good idea to post such a long url in the document. Use a small name and use that for the link. But if this is what you want:

\documentclass[10pt,letterpaper]{article}

\usepackage{hyperref}
\usepackage{longtable}

\renewcommand{\UrlBreaks}{\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\/\do\-\do\_\do\:\do\.}

\begin{document}
\small

\def \myURL {http://www.washingtonpost.com/business/technology/target-data-breach-affects-40-million-accounts-payment-info-compromised/2013/12/19/5cc71f22-68b1-11e3-ae56-22de072140a2_story.html}

\begin{longtable}{@{}p{9.45cm}}

Craig Timberg, Jia Lynn Yang, and Hayley Tsukayama, ``Target says 40 million credit, 
debit cards may have been compromised in security breach'', \emph{The Washington Post}, 
December 19, 2013, available: \href{\myURL}{\nolinkurl{\myURL}}. \\

\end{longtable}
\end{document}
share|improve this answer
    
Hi, thanks for the reply. In your example the line ending "-payme" is still one character short, as is the line below that. In other words, there is still no left and right justification of the URL. –  andrewinfosec Aug 1 at 3:41
    
@andrewinfosec without a lot of changes tex only justifies by altering white space. there is no white space in the later lines and probably there is not (quite) enough space for an extra letter. –  David Carlisle Aug 1 at 9:33
    
Hi. It's hard to tell visually whether there's room for another character or not, but it certainly doesn't look right justified :-( –  andrewinfosec Aug 1 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.